<?php
setcookie('a', $_SERVER['REQUEST_URI']);
header(location: "index2.php");
?>
我是 .htaccess 的新手,想知道如何将此 php 脚本转换为 .htaccess 代码
以下是我用 .htaccess 尝试过的行,但没有用:
Header set Set-Cookie a=REQUEST_URI
Header set Set-Cookie "a=REQUEST_URI; path=/;"
Header set Set-Cookie "language=%{REQUEST_URI}e; path=/;"
在 mod_rewrite 中有什么方法可以做到这一点吗?
:)
最佳答案
因为您提到了 mod_rewrite,所以我能够使用以下 mod_rewrite .htaccess 代码来产生您想要的效果:
RewriteEngine On
RewriteRule ^(.+)/?$ index2.php [CO=testcookie:%{REQUEST_URI}:localhost,R,L]
我获得了一个包含当前 URI 的 cookie 集,并按预期重定向到 index2.php。
CO
设置一个 cookie (name:value:domain),R
是重定向,L
表示“最后一条规则”。当然,您必须适本地更改 cookie 域、路径和生命周期信息。更多信息 here .
这就是您要实现的目标吗?
关于PHP 到 htaccess?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5532422/