htaccess rewrite condition old site to new site with querystring

Posted by Brandon Braner on Server Fault See other posts from Server Fault or by Brandon Braner
Published on 2013-10-17T15:05:04Z Indexed on 2013/10/22 15:56 UTC
Read the original article Hit count: 151

I am not even going to pretend to fully understand how htaccess rewrite conditions work. I've been working on this for a while searching and searching.

I have an old Wordpress site www.old-site.com and a new site www.site.com. Wordpress uses query strings page_id=# to redirect to pages.

On the old site page_id=2 went to a specific page but on the new site it goes the the home page.

I need old-site/?page_id=2 to go to site.com/our-company

Here is what I am trying

RewriteCond   %{HTTP_HOST} ^(www\.)?old-site.com$ [NC]
RewriteCond   %{QUERY_STRING}   ^page_id=2$ 
RewriteRule   ^(.*)$ http://www.site.com/our-company/ [R=301,L]

If I take out the rewrite condition for query string it redirects all traffic from old-site.com to the company page on the new site. Where am I going wrong?

I have about 15 redirects I need to do this way.

© Server Fault or respective owner

Related posts about .htaccess

Related posts about mod-rewrite