301 Redirect Issue With Query String

730promo

Junior Member
Joined
Aug 27, 2009
Messages
135
Reaction score
16
Hi guys,
I was hoping someone could give me some advice with 301 redirect. I have recently moved domains and got a redirect on my domain from the old one to the new one. This works for all of the files except ones with have a query string in the URL.
e..g
www.olddomain.com/example.php - redirect to index of new site
www.olddomain.com/example/ - redirect to index of new site
www.olddomain.com/example?id=2 - redirects to the new site but to the 404 page.

My current 301 redirect reads.
#RewriteRule ^(.*)$ "http\:\/\/www\.olddomain\.com\/$1" [R=301,L]
RewriteRule ^(.*)$ "http\:\/\/www\.newsite\.com\/" [R=301,L]

Can anyone advise me of what code to put into the htaccess file so i can redirect ALL urls WITH a query string to the index page of the new site

Thanks in advance
 
Last edited:
So you want to redirect ALL URLs to the index page?

Use this in .htaccess:
redirect 301 / http://YourIndexPageUrl
 
Hi you would do something like this:

RewriteCond %{QUERY_STRING} ^id=2$ [NC]
RewriteRule ^www\.olddomain\.com/example$ /www.newdomain.com/newpath [R=301]

Edit:
Totally misread the question! But if you want to redirect exact query strings to exact pages you'd do something like this.
 
hi guys yeh just to clarify im looking to redirect all urls that have a query string to the main page. 90% of all the pages on the site are redirected to the index page with the exception of a few.

So i take it as going to a query string on the old site takes me to a 404 on the new one the query string is passed over in the redirect. so www.oldsite.com/example?=2 would take you to www.newdomain.com?=2 and thats where the 404 is coming from?
 
Back
Top