问题
I need to add style=2
to all urls within a directory ONLY if the url does NOT already contain style=2
.
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?
回答1:
Change your code to this to make it work:
RewriteCond %{QUERY_STRING} !(^|&)style=2(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?style=2 [R=301,L,QSA]
回答2:
Try this :
RewriteCond %{QUERY_STRING} !^(.*&)?style=
RewriteRule ^(.*)$ /$1?style=2 [L,QSA,R=301]
来源:https://stackoverflow.com/questions/13066142/htaccess-redirect-if-query-string-variable-present