RewriteCond - 如何逃避这个?

时间:2011-12-08 15:59:59

标签: apache .htaccess mod-rewrite

您在重写此网址时遇到问题 - 如何将其撤消以便自行更正?

网址被发送到公共领域,如下:

http://www.domain.com/directory/directory-2/10018485&key=3945

我需要写一条规则来纠正它:

http://www.domain.com/directory/directory-2/10018485?key=3945

` 是这样做的,没有成功......

RewriteCond %{REQUEST_URI} \/directory\/directory-2\/10018485&key=3945
RewriteRule ^(.*)$ /directory/directory-2/?id=10018485&key=3945 [L]

谢谢:)

1 个答案:

答案 0 :(得分:0)

你不需要逃避&在%26的比赛中。你有什么工作对我来说很好,不知道为什么它不适合你。但是你不需要RewriteCond,你可以将2组合成一个规则。当实际请求为/directory/directory-2/10018485&key=3945directory/directory-2/10018485%26key=3945

时,这些对我有用
RewriteRule ^directory/directory-2/10018485&key=3945$ /directory/directory-2/?id=10018485&key=3945 [L]

更抽象的意义:

RewriteRule ^directory/directory-2/([0-9]+)&key=([0-9]+)$ /directory/directory-2/?id=$1&key=$2 [L]