A
A
Anumik2016-08-30 12:31:01
Apache HTTP Server
Anumik, 2016-08-30 12:31:01

What is the correct way to use mode_rewrite?

Good day
I need to replace URLs like where site.com/...the site.com/city/...city value is set in the cookie, I know how you can change the URL in .htaccess for the user, but how to make the logic

if ($_COOKIE['CITY']=1)
{...} 
elseif 
($_COOKIE['CITY']=2)
{...}...

I don’t understand, is it possible to use conditions somehow in .htaccess or to change the URL in the same way through php?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Novikov, 2016-08-30
@Anumik

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_COOKIE} cookie_name=([^;]+) [NC]
RewriteRule ^(.*)$ http://site.com/%1 [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question