trim query string(s) from url

戏子无情 提交于 2019-12-08 11:29:39

问题


Some urls are generated via our script. I need to trim all these via htaccess; I have a few hundred of them, so all ?xxx have to be cleaned.

ie:

domain.com/page.html?word=gclid=4nwseuoSg 

to

domain.com/page.html 

or anything starting with ?, the ? and the rest is not needed.

I tried RewriteRule ^\?(.*)$ / [R=301,L] but did not work :(

What do I have to use instead of \?(.*) ?


回答1:


the path doesn't contain the querystring. Use RewriteCond to match any none-empty querystring.

RewriteCond %{QUERY_STRING}  !^$
RewriteRule \.html$ $0 [R=301,L]

I also added a condition that the url has to end in .html just in case you want to add some php script in the future.



来源:https://stackoverflow.com/questions/8669755/trim-query-strings-from-url

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