gpt4 book ai didi

apache - 如何通过 mod_rewrite 编辑 cookie 集?

转载 作者:行者123 更新时间:2023-12-04 15:35:01 27 4
gpt4 key购买 nike

我使用 mod_rewrite 来设置一些 cookie,然后将用户重定向到目标 url。由于这些 cookie 用于第三方环境,我必须设置标志 SameSite=none。
我试图通过 mod_headers 编辑 Set-Cookie header ,但我没有让它工作。

我的 Apache 配置:

<VirtualHost *:80>
ServerName www.example.test
RewriteEngine on
RewriteRule ^/test/(.*)$ /test/$1 [CO=cookie1:1:.example.test:86400:/:true:true]
RewriteRule ^/test/(.*)$ /test/$1 [CO=cookie2:$1:.example.test:86400:/:true:true]
RewriteRule ^/test/(.*)$ http://www.example.test/test2/$1 [R,L]
Header always edit Set-Cookie ^(.*)$ "$1; SameSite=none"
Header always set X-Foo "bar"
Header always edit X-Foo ^(.*)$ "$1; SameSite=none"
</VirtualHost>


我的测试要求:
Connecting to 127.0.0.1:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 302 Found
Date: Tue, 04 Feb 2020 09:12:23 GMT
Server: Apache/2.4.6 (CentOS) PHP/7.2.27
X-Foo: bar; SameSite=none
Set-Cookie: cookie1=1; path=/; domain=.example.test; expires=Sat, 04-Apr-2020 09:12:23 GMT; secure; HttpOnly
Set-Cookie: cookie2=0815; path=/; domain=.example.test; expires=Sat, 04-Apr-2020 09:12:23 GMT; secure; HttpOnly
Location: http://www.example.test/test2/0815
Content-Length: 218
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
Cookie coming from 127.0.0.1 attempted to set domain to 127.0.0.1
Cookie coming from 127.0.0.1 attempted to set domain to 127.0.0.1
Location: http://www.example.test/test2/0815

为什么编辑了 X-Foo header ,而未编辑 Set-Cookie header ?

最佳答案

我终于明白了 - 您可以在 RewriteRule 中设置 SameSite 标志:

<VirtualHost *:80>
ServerName www.example.test

RewriteEngine on

RewriteRule ^/test/(.*)$ /test/$1 [CO=cookie1:1;\ SameSite=none:.example.test:86400:/:true:true]
RewriteRule ^/test/(.*)$ /test/$1 [CO=cookie2:$1;\ SameSite=none:.example.test:86400:/:true:true]

RewriteRule ^/test/(.*)$ http://www.example.test/test2/$1 [R,L]

</VirtualHost>

现在我得到以下回复:

wget --server-response --header "主机:www.example.test""http://127.0.0.1/test/0815"
--2020-02-05 11:15:15-- http://127.0.0.1/test/0815
连接到 127.0.0.1:80... 已连接。
HTTP 请求已发送,正在等待响应...
发现 HTTP/1.1 302
日期:2020 年 2 月 5 日,星期三 10:15:15 GMT
服务器:Apache/2.4.6 (CentOS) PHP/7.2.27
设置-Cookie:cookie1=1; SameSite=none;路径=/;域=.example.test; expires=Sun, 05-Apr-2020 10:15:15 GMT;安全的;仅Http
设置-Cookie:cookie2=0815; SameSite=none;路径=/;域=.example.test; expires=Sun, 05-Apr-2020 10:15:15 GMT;安全的;仅Http
位置:http://www.example.test/test2/0815
内容长度:218
保持事件:超时=5,最大=100
连接:保持事件
内容类型:文本/html;字符集=iso-8859-1
来自 127.0.0.1 的 Cookie 试图将域设置为 127.0.0.1
来自 127.0.0.1 的 Cookie 试图将域设置为 127.0.0.1
位置:http://www.example.test/test2/0815 [以下]

关于apache - 如何通过 mod_rewrite 编辑 cookie 集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60054089/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com