Origin
Origin

Reputation: 69

.htaccess rewrite url based on cookie variable

i'm trying to rewrite url to existing file dynamically. This is the static example :

DirectoryIndex load.php live.php
Options +FollowSymlinks
RewriteEngine On

RewriteRule ^cole$ live.php

as expected, this works fine, when any page in same root calls cole, it redirects to live.php.

Now, i want to redirect to page live.php but replace cole with cookie dynamic value.

I tried this :

DirectoryIndex yosh.php

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_COOKIE} cookieName=([^;]+) [NC]

RewriteRule  ^(.*)$ pimp.php [QSA,L]

It doen't work, just displays a 404 not found page. Note that i use WAMP.

Any idea on how to do that ?

Upvotes: 0

Views: 821

Answers (1)

Croises
Croises

Reputation: 18671

You can use:

RewriteCond %{HTTP_COOKIE} cookieName=([^;]+) [NC]
RewriteCond %{REQUEST_URI} /%1/?$ [NC]
RewriteRule  ^ /sub/pimp.php [QSA,L]

Upvotes: 1

Related Questions