Remove Query String from Rootdomain

梦想与她 提交于 2019-12-13 02:35:35

问题


I know with a simple redirect one (Sub-)Domain or Folder to another i can get rid of a string like this

RewriteEngine On
RewriteRule (.*) http://www.domain.tld/? [R=301,L]

I know how to get rid of it when it is a simple file too.

But when it comes to the Rootdomain itself (http://domain.tld/?Stringwhatsoever), i am at a loss here. My last try used a modified version of a redirect I used to redirect files and folders around and that worked pretty nicely and also removed the query, but it ended up in a redirection error.

RewriteRule ^ http://domain.tld/? [L,NC,R=301]

So i have no clue how to get rid of Query Strings at urls without breaking it.


回答1:


Try this :

RewriteEngine On
RewriteCond %{THE_REQUEST} /\?([^\s]+) [NC] 
RewriteRule ^$ http://domain.com/? [NC,R,L]

Or

RewriteEngine On
RewriteCond %{QUERY_STRING} (.+) [NC] 
RewriteRule ^$ http://domain.com/? [NC,R,L]

Reference :

-https://wiki.apache.org/httpd/RewriteQueryString



来源:https://stackoverflow.com/questions/31552598/remove-query-string-from-rootdomain

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