htaccess - add string to end url

2019-08-15 06:29发布

The url is like

http://www.example.com/?p=3733&preview=true

and I want to add ?ModPagespeed=noscript

so it becomes http://www.example.com/?p=3733&preview=true?ModPagespeed=off

p= is dynamic btw

Any ideas?

1条回答
放我归山
2楼-- · 2019-08-15 06:52

put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)p=[^&]+
RewriteCond %{QUERY_STRING} (^|&)preview=true(&|$)
RewriteCond %{QUERY_STRING} !(^|&)ModPagespeed=off(&|$)
RewriteRule ^$ %{REQUEST_URI}?ModPagespeed=off [L,QSA,R]

UPDATE: If you want final URL with 2 ? in it, use this rule:

RewriteCond %{QUERY_STRING} (^|&)p=[^&]+
RewriteCond %{QUERY_STRING} (^|&)preview=true(&|$)
RewriteCond %{QUERY_STRING} !(^|&)ModPagespeed=off(&|$)
RewriteRule ^$ %{REQUEST_URI}?%{QUERY_STRING}?ModPagespeed=off [L,NE,R]
查看更多
登录 后发表回答