mod_rewrite:为什么 apache 对 %{HTTP_COOKIE} 进行 URL 编码?

发布于 2024-10-04 03:52:43 字数 455 浏览 0 评论 0 原文

我正在尝试匹配 cookie 中的值。问题是,Apache 对值进行了 url 编码。所以,如果我这样做:

RewriteCond %{HTTP_COOKIE} ^(.+)$ [NC]

它将捕获这个:

session%3DeXnR1oDL1Reb8Z3Gdgk7Sg%26account%3D2%3B

而不是这个:

session=eXnR1oDL1Reb8Z3Gdgk7Sg&account=2

所以没有办法获取帐号来执行此操作:

RewriteRule ^$ /accounts/%1/ [R=301,L]

请帮忙!我在 Google 和 stackoverflow 上到处查看,但没有人解决这个问题。太感谢了。

I am trying to match a value in a cookie. The problem is, Apache makes the value url-encoded. So, if I do this:

RewriteCond %{HTTP_COOKIE} ^(.+)$ [NC]

It will capture this:

session%3DeXnR1oDL1Reb8Z3Gdgk7Sg%26account%3D2%3B

instead of this:

session=eXnR1oDL1Reb8Z3Gdgk7Sg&account=2

So there is no way to get the account number to do this:

RewriteRule ^$ /accounts/%1/ [R=301,L]

Please help! I have looked everywhere on Google and stackoverflow and no one has addressed this issue. Thank you so much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

去了角落 2024-10-11 03:52:43

我从未找到答案——但是,我确实找到了解决方法。对于那些遇到同样问题的人,这里是:

使用不会进行 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!

北方的韩爷 2024-10-11 03:52:43

您是否尝试过使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文