301 redirect with ? (question mark) not working in htacces

4.4k views Asked by At

This is probably an easy question, but we can not find why the 301 is not working. When we have a url with a question mark the 301 redirect in our .htacces is not working. For example:

/order/order.html?AddID=1078&Rand=666171759380936096

so: Redirect 301 /order/order.html?AddID=1078&Rand=666171759380936096 http://www.domain.nl

In our webmaster tools we have 8000 url's with the same structure /order/order.html?AddID=.... that say 404 not found. We want to 301 redirect them to the homepage, but we get a 404 not found page instead. when we use the same redirect with only /order/order.html he is redirected correct.

2

There are 2 answers

4
Jon Lin On BEST ANSWER

You can't match against the query string in a Redirect statement, use mod_rewrite and match against the %{QUERY_STRING} var:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^AddID=1078&Rand=666171759380936096$
RewriteRule ^order/order.html$ http://www.domain.nl/? [L,R=301]

But since you have like 8000 URLs that start with the query string ?AddID=, then you can just match against that:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^AddID=[0-9]
RewriteRule ^order/order.html$ http://www.domain.nl/? [L,R=301]
0
Coen On

I have just tried it again and now I placed it right in the top of the htacces, see printscreen. In this case it is about the url (normally I do not place my own url) www.tablet.nl and if you place one of our 404 pages /order/order.html?AddID=1037&Rand=539054443213186002 behind the url, /order/order.html is deleted and only ?AddID=1037&Rand=539054443213186002 is shown behind the main url with a 404 page not found.

Any idea and I let the htacces as shown in the attachement so you can test the url.

Let me know

enter image description here