im new for .htaccess and wonder how to conve...">

PHP for htaccess?

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

im new for .htaccess and wonder how to convert this php script to .htaccess code

here are the lines that I tried using .htaccess but not working:

 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 to do this in mod_rewrite?

:)

+4
source share
2 answers

Since you mentioned mod_rewrite, I was able to use the following mod_rewrite.htaccess code to get the desired effect:

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

I get a set of cookies with the current URI and redirected to index2.php, as expected.

CO sets a cookie (name: value: domain), R redirected, L means "last rule". Of course, you will need to change the cookie domain, the path information, and your whole life if necessary. More info here .

Is this what you tried to accomplish?

+1
source

I also get experience using .htaccess files, but from what I see in several other works, you may need to save the code in a script, if you are trying to set a certain cookie duration you will need to save it in a PHP script, while cookie a session-based file is possible in a .htaccess file. This link may help with your approach: http://www.webmasterworld.com/apache/3694277.htm

0
source

Source: https://habr.com/ru/post/1346473/


All Articles