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

纵然是瞬间 提交于 2019-12-13 04:34:54

问题


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.


回答1:


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]



回答2:


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



来源:https://stackoverflow.com/questions/18493473/301-redirect-with-question-mark-not-working-in-htacces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!