【发布时间】:2017-05-23 09:06:34
【问题描述】:
我正在尝试在 url 重写上设置一些非常具体的条件,但我很挣扎。
假设我有一个类似http://www.example.com/?product=test&retailer=test&site=test的网址
在这种情况下(存在product 参数),我只想删除&site=test,但不更改url 的其余部分。
如果product 参数不存在,例如http://www.example.com/?retailer=test&site=test
我仍然想删除&site=test 并将?retailer=test 更改为/retailer/test,因此完整的网址将是http://www.example.com/retailer/test。我也只希望这发生在根域上。甚至只是为了删除site参数也很挣扎......
我试过了:
RewriteCond %{QUERY_STRING} (?:^|&)sitechange=([^&]+) [NC]
RewriteRule ^$ ? [L,R=301]
但这会删除所有实例中的所有参数
也试过这个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.*)?&?site=[^&]+&?(.*)? [NC]
RewriteCond %{REQUEST_URI} /(.*)
RewriteRule .* %3?%1%2? [R=301,L]
但这没有任何作用。发现很难理解这些重写规则。如果有人可以帮助我将不胜感激
【问题讨论】:
标签: apache .htaccess mod-rewrite url-rewriting