如果htaccess的重定向查询字符串变量present
问题描述:
我需要添加样式= 2
到一个目录只有当URL不已经包含之内的所有网址样式= 2
。
I need to add style=2
to all urls within a directory ONLY if the url does NOT already contain style=2
.
在根目录,我有以下一个.htaccess:
Within the directory root, I have an .htaccess with the following:
RewriteCond %{QUERY_STRING} !(?style=|&style=)
RewriteRule ^(.*)$ %1&style=2? [R=301,QSA]
我知道这是错的。任何人都可以帮忙吗?
I know it's wrong. Can anyone help?
答
更改code本,使其工作:
Change your code to this to make it work:
RewriteCond %{QUERY_STRING} !(^|&)style=2(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?style=2 [R=301,L,QSA]