gpt4 book ai didi

.htaccess - 如何根据 cookie 值进行 htaccess 重定向

转载 作者:行者123 更新时间:2023-12-04 07:29:14 27 4
gpt4 key购买 nike

我在 Google 上失败了,在这里搜索找不到答案。抱歉,我是 htaccess 的新手,它的语法真的很奇怪,而且很难学!

你可以在这里看到我想要做什么......

RewriteEngine on
RewriteCond %{HTTP_COOKIE} ^.*user_id=(\d+).*$ [NC]
RewriteRule .* http://localhost/mysite/cache/$1 [R=301,L]
RewriteRule .* http://localhost/mysite/cache/guest [R=301,L]

我正在为每个用户缓存页面以提高加载速度。如果他们使用 cookie 登录,我想重定向到正确的 HTML 缓存文件夹,否则我想加载 guest 缓存。

现在它进入一个 infi 循环。如果我删除 [R=... 那么我会收到内部服务器错误。

请帮忙!!!谢谢你!!!

最佳答案

这适用于像 id=1234 这样的 cookie :

RewriteEngine on
RewriteCond %{HTTP_COOKIE} ^id=([0-9]*)$ [NC]
RewriteRule .* http://localhost/mysite/cache/%1 [R=301,L]
RewriteRule .* http://localhost/mysite/cache/guest [R=301,L]

现在针对您的问题:
确保您的 htaccess 不适用于您重写的页面!例如,如果您的 .htaccess 位于 /mysite/.htaccess
它将再次用于
http://localhost/mysite/cache/%1

这可能是你无限循环的原因。要解决此问题,请确保 htaccess 规则未应用于子目录或使用其他目录作为缓存。

关于.htaccess - 如何根据 cookie 值进行 htaccess 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3978726/

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