I am trying to setup rewrite rules for a custom homepage because we are planning on using full-screen slides and using a javascript pushstate to update the url instead of using formal WordPress pages. We decided using GET variables would be easiest in order to allow linking to a certain slide on the homepage, but it's not nice looking so I wanted to use rewrite rules in order to make everything slick and SEO friendly.
Here's a few examples of what we are trying to do ("slide" is not a page/post in WP):
Nice URL: example.com/slide/something/
Ugly URL: example.com/?slide=something
Nice URL: example.com/slide/videos/
Ugly URL: example.com/?slide=videos
Now, we have no problem with the ugly URLs, but my rewrite rule for this just isn't working. I have gone through several questions/answers on this but none of the accepted answers have been working. Here's what I have in functions.php:
add_action('init', 'add_rewrite_rules');
function add_rewrite_rules() {
flush_rewrite_rules();
add_rewrite_rule(
'^slide/([^/]*)/?$',
'index.php?slide=$matches[1]',
'top'
);
}
I'm flushing rewrite rules while I try to get this working; I realize I shouldn't have this in there, being called on every refresh if this was a production site.
If I try to go to example.com/slide/something/ I am redirected to the homepage.