从URL内饰查询字符串(S)字符串、内饰、URL

2023-09-02 20:34:33 作者:不在服务区╮

通过我们的脚本生成的某些URL。我需要通过htaccess的修剪所有这些; 我对他们有几百个,因此所有?xxx将必须清洗。

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.

例如:

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

domain.com/page.html 

或任何开始?,α-并且不需要的其余部分。

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

我试过重写规则^ $ / [R = 301,L] ,但没有工作?(*):(

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

我有什么用,而不是 ?(。*)

推荐答案

不包含查询字符串的路径。使用的RewriteCond匹配任何没有空的查询字符串。

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

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

我还添加了一个条件,即URL已结束在的.html 以防万一你要添加在未来的一段PHP脚本。

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.