开发者

PHP to htaccess?

<?php
    setcookie('a', $_SERVER['REQUEST_URI']);
    header(location: "index2.php");
?>

im new to .htaccess and won开发者_运维百科der how to convert this php script to .htaccess code

here are lines what I tried with .htaccess, but din't work:

Header set Set-Cookie a=REQUEST_URI
Header set Set-Cookie "a=REQUEST_URI; path=/;"
Header set Set-Cookie "language=%{REQUEST_URI}e; path=/;"

is there any way of doing this in mod_rewrite?

:)


Because you mentioned mod_rewrite, I was able to use the following mod_rewrite .htaccess code to produce the effect you want:

RewriteEngine On
RewriteRule ^(.+)/?$ index2.php [CO=testcookie:%{REQUEST_URI}:localhost,R,L]

I get a cookie set with the current URI and a redirect to index2.php as expected.

CO sets a cookie (name:value:domain), R is redirect, L means "last rule". Of course, you'll have to change cookie domain, path and lifetime information as appropriate. More information here.

Is this what you were trying to accomplish?


I am gaining experience in using .htaccess files as well but from what I've see in a few other's work, you may need to keep your code in a script if you're trying to set a specific-duration cookie you will have to keep it in a php script while a session based cookie is possible in the .htaccess file. This link may help with your approach: http://www.webmasterworld.com/apache/3694277.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜