0

My old Wordpress blog didn't use pretty permalinks and instead used the ugly query strings to determine the page/article. I have moved my blog from 'blog.domain.com' to 'newblog.domain.com' and I'm trying to redirect all old page URLs with the ugly query string to my new blog homepage. I want to do this for all query strings EXCEPT the Wordpress search query ?s=

How can I 301 redirect all query strings except the search query to my new blog homepage?

I know how to redirect ALL query strings, but how do I exclude only the search query?

Ty Bailey
  • 2,392
  • 11
  • 46
  • 79

1 Answers1

0

If you have a 404.php template in your theme, above the get_header(), check to see if the $_GET variable 's' is being used...

if(isset($_GET['s'])) {

    //DON'T do redirect

} else {

    //redirect now
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: " . $new_url);

}
Pedro
  • 451
  • 2
  • 5
  • I would prefer to 301 redirect for SEO purposes – Ty Bailey May 16 '14 at 16:35
  • See edits -- you can do a 301 redirect in php. How you go about getting the $new_url var is up to you, but you could use the get_permalink() function based upon the id from the URL – Pedro May 16 '14 at 16:37