Redirect page to homepage, keeping URL
I'm creating a site where every page is really rendered on a single page - the homepage. I'd like to make it so page URLs - like /about-us/
- redirect back to the homepage, but keep the same URL (/
). For example, if I visit http://example.com/about-us/
, I want to see http://example.com/
(scrolled down to the correct section, thanks to some JS), but with the URL still as http://example.com/about-us/
.
The template_include
action seems like it'd work, but doing this:
function home_template($template) {
return locate_template(array('index.php'));
}
add_action('template_include', 'home_template');
causes a full redirect to the homepage for some reason (URL and all). Not sure why. Moving the homepage template to home.php
or front_page.php
(and update the above code accordingly) doesn't fix the issue.
add_rewrite_rule
also seemed promising, but it also seems to simply redirect to the homepage, at least with the following code:
function home_rewrite() {
add_rewrite_rule('about-us', 'index.php', 'top');
}
add_action('init', 'home_rewrite');
wp_redirect
also doesn't do what I'm looking for.
Any ideas? Thank you!!
Topic template-include rewrite-rules url-rewriting permalinks Wordpress
Category Web