0

I have a client that changed jobs. He wants to redirect all pages on the wordpress site to a specific page on that site. But he also wants to keep all the SEO from the blog posts. So I need all the blog posts to show up, but redirect any old pages to the new page. So, for example:

oldpage.com > oldpage.com/specificpage

so anything that is not a blog post goes to oldpage.com/specificpage

the blogpost would go to blogpost

I am able to redirect everything to oldpage.com/specificpage

I have excluded the homepage and /wp-admin/ etc.

But there are over 4,000 posts and to redirect each one individually is impractical Is there a way to redirect everything except the posts through .htaccess?

2
  • What are your permalink settings like? Are blogposts on a distinguishable path such as example.com/blog/{post slug}?
    – bosco
    Apr 24 at 20:31
  • Yes. Each post has a distinct name. Apr 25 at 21:39

1 Answer 1

0

You can either add the following code to your functions.php or create a custom plugin with the code.

function my_custom_page_redirect() {
  if (is_page()) {
    wp_redirect(home_url());
    exit;
  }
}
add_action('template_redirect', 'my_custom_page_redirect');

Note - change the URL in wp_redirect() to whatever the 'specificpage' is. I just used home_url() in the redirect as an example.

4
  • From the Codex: Note: wp_redirect() does not exit automatically, and should almost always be followed by a call to exit;:
    – Abhik
    Apr 25 at 6:58
  • Good catch @Abhik and thanks for pointing that out, missed that point.
    – ScottM
    Apr 25 at 10:39
  • I updated the code sample to include the call to exit;.
    – ScottM
    Apr 25 at 11:21
  • Is there a way to do this through .htaccess? Apr 25 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.