如何更改与mod_rewrite的一个cookie的名字吗? [英] How to change a cookie name with mod_rewrite?

查看:166
本文介绍了如何更改与mod_rewrite的一个cookie的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变这种状况是由AWS ELB设置cookie的名字,但保留其值与重写条件和重写规则。

I'm trying to change the name of a cookie that's set by an AWS ELB, but keep its value with a rewrite condition and rewrite rule.

下面是我到目前为止已经进行管理:

Here's what I've managed so far:

RewriteCond %{HTTP_COOKIE} AWSELB=(^BD.*) [NC]
RewriteRule ^(.*) - [CO=SIMELB:%1:.amazonaws.com:lifetime:-1]

显然重写规则是不正确的,但可能有人帮助我正确的语法?

Obviously the RewriteRule is incorrect, but could someone help me with the right syntax?

推荐答案

好吧,评论跟帖以下,我认为有足够的信息来上手。最重要的是,你的
模式没有因为(BD ^ *)拍摄组的工作,特别是因为
^ 主播。相反,捕捉(BD [^;] +)抓住一切直到下一个; (或
字符串的结束时,如果没有一个)。

Ok, following the comment thread, I think there's enough info to get started. Foremost, your pattern doesn't work because of the (^BD.*) capture group, and in particular because of the ^ anchor. Instead, capture (BD[^;]+) to grab everything up to the next ; (or the end of the string if there isn't one).

要明确取消设置previous饼干,其他的例子使用无效修改,虽然我
无法找到对应的文档。

To explicitly unset the previous cookie, other examples use the INVALID modifier, though I cannot find the documentation for it.

Apache的mod_rewrite文档上
饼干

RewriteCond %{HTTP_COOKIE} AWSELB=(BD[^&]+) [NC]
# Delete the old one
RewriteRule ^ - [CO=AWSELM:INVALID:.amazonaws.com:0:/:-1]
# Add the new one
# Specify your lifetime in minutes or 0 for the browser session (60 below)...
# ALso add the path
# Assumimg the -1 is for insecure cookies
RewriteRule ^ - [CO=SIMELB:%1:.amazonaws.com:60:/:-1]

对于旧的cookie被成功取消设置,无论是域名,将需要的路径
准确匹配最初由AWS设置。检查当前设置的饼干和使
一定要匹配域和放大器;路径。

For the old cookie to be successfully unset, both the domain and the path will need to exactly match those originally set by AWS. Inspect the cookies currently being set and make sure you match the domain & path.

和真的,这是没有必要的,以匹配 BD ...你也可以同样做 AWSELB =([^;] + ),因为它只能匹配以下分号反正。

And really, it isn't necessary to match BD... You could just as well do AWSELB=([^;]+) because it must only match up to the following semicolon anyway.

如果该值正在消失,这可能是因为在的RewriteCond 只适用于第一个后续匹配重写规则。您可以随时重复刚才的的RewriteCond 。这是丑陋的,不幸的是,但我测试了它,发现它才能正常工作。

If the value is being lost, it may be because the the RewriteCond is only applied to the first subsequent matching RewriteRule. You can always just repeat the RewriteCond. This is ugly, unfortunately, but I tested it and found it to work correctly.

# no capture group the first time since you don't use it until later
RewriteCond %{HTTP_COOKIE} AWSELB=BD.+ [NC]
RewriteRule ^ - [CO=AWSELM:INVALID:.amazonaws.com:0:/:-1]
# This will continue to execute since the previous didn't have [L]
RewriteCond %{HTTP_COOKIE} AWSELB=(BD[^&]+) [NC]
RewriteRule ^ - [CO=SIMELB:%1:.amazonaws.com:60:/:-1]

(注意:你不会看到更新,直到随后的HTTP请求中的cookie值;也就是说,如果你试图与Apache设置后立即从您的脚本检查它,新的值不会是present因为cookie头具有使一个往返行程返回给客户端)

(Note: you won't see the cookie value updated until a subsequent HTTP request; that is, if you tried to inspect it from your script right after setting it with Apache, the new value won't be present because the cookie header has to make a round trip back to the client)

这篇关于如何更改与mod_rewrite的一个cookie的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆