mod_rewrite:为什么 apache 对 %{HTTP_COOKIE} 进行 URL 编码?
我正在尝试匹配 cookie 中的值。问题是,Apache 对值进行了 url 编码。所以,如果我这样做:
RewriteCond %{HTTP_COOKIE} ^(.+)$ [NC]
它将捕获这个:
session%3DeXnR1oDL1Reb8Z3Gdgk7Sg%26account%3D2%3B
而不是这个:
session=eXnR1oDL1Reb8Z3Gdgk7Sg&account=2
所以没有办法获取帐号来执行此操作:
RewriteRule ^$ /accounts/%1/ [R=301,L]
请帮忙!我在 Google 和 stackoverflow 上到处查看,但没有人解决这个问题。太感谢了。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未找到答案——但是,我确实找到了解决方法。对于那些遇到同样问题的人,这里是:
使用不会进行 URL 编码的字符分隔您的子 cookie 值。我使用了破折号“-”。例如“VAL1--VAL2”。
祝你好运!
I never did find the answer -- BUT, I did find a work-around. For those having the same problem, here it is:
Separate your sub-cookie values using a character that will NOT get URL encoded. I used the dash character "-". e.g. "VAL1--VAL2".
Good luck!
您是否尝试过使用 flag -> NE|没有逃脱?
默认情况下,特殊字符,例如 &例如, 和 ? 将被转换为其等效的十六进制代码。使用 [NE] 标志可以防止这种情况发生。
RewriteRule ^/anchor/(.+) /bigpage.html#$1 [NE,R]
上面的示例将 /anchor/xyz 重定向到 /bigpage.html#xyz。省略 [NE] 将导致 # 转换为其等效的十六进制代码 %23,这将导致 404 Not Found 错误情况。
来源:http://httpd.apache.org/docs/2.3/rewrite/flags .html
Did you try using flag -> NE|noescape ?
By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.
RewriteRule ^/anchor/(.+) /bigpage.html#$1 [NE,R]
The above example will redirect /anchor/xyz to /bigpage.html#xyz. Omitting the [NE] will result in the # being converted to its hexcode equivalent, %23, which will then result in a 404 Not Found error condition.
Source: http://httpd.apache.org/docs/2.3/rewrite/flags.html