问题
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