Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Mod rewrite and cookies

Has anyone got mod rewrite to act on cookies?



9:20 pm on Mar 24, 2001 (gmt 0)

10+ Year Member

I've spent some time trying to get mod rewrite to act on cookies using the HTTP_COOKIE header, but no joy. I'm not the greatest at regular expressions but can't find any examples of a known working config to confirm.

I've read [httpd.apache.org...] and Ralf S. Engelschall's articles, but still stuck.

If anyone has a working example I would be grateful if you could post it, it will send me off in the right direction.


5:28 pm on Mar 25, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

tpk - I was hoping someone with some useful info would jump in here, no joy I'm afraid. Although I'm fairly familiar with mod_rewrite, I haven't yet worked with cookies...

I'll bring your question to the attention of the other mods in the mods forum, hopefully someone can provide some ideas, we have some real sharp folks here...


5:56 pm on Mar 25, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

>trying to get mod rewrite to act on cookies

I'm not very clear on what you mean by this tpk, setting/retrieving cookies using mod_rewrite? The usual way is to use some server side language to do this, so not sure if by "act" you mean something else.


11:18 pm on Mar 25, 2001 (gmt 0)

10+ Year Member

Dave, thanks.

Air - well I have javascript and perl on the site that sets/gets cookies. I want to use mod_rewrite to rewrite the url to a different one if the user has a cookie. If you look at [httpd.apache.org...] it seems to suggest you can, but in practise it just doesnt work.

It may help a little if I describe what I want, the site has a little egotistical flash animation on the front page :-) but I don't want to bore repeat visitors with it, so if they have a cookie (which my tracking system will have given them on their previous visit) I want their visit to www.mydomain.com to be rewritten to www.mydomain.com/main.html invisibly. The rest of the site is all dynamic, but the URL's are tidied up to real looking URL's using mod_rewrite so I know it works - its just this cookie thing thats got me stumped.

Searching on the net I can only find one other person asking the same question (no solutions though unfortunately).

I've tried the following

RewriteCond %{HTTP_COOKIE} uin
RewriteRule ^/.*$ /main.html [L]

and a few variations but get nothing. The cookie's name is uin and this should match it but it doesnt appear to.

I could get around this using perl/javascript but neither of these would be as elegant as I would like.


2:03 am on Mar 26, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Ok, I get what you want to do now :))

Try it like this:

RewriteEngine on
RewriteCond %{HTTP_COOKIE} uin
RewriteRule /* [%{HTTP_HOST}...] [R,L]

The id must match the cookie name, and main.html I threw in there 'cause you had it, don't know if that is the actual page you want to go to.

[added]modified the expression - the first didn't work in all instances[/added]


Featured Threads

Hot Threads This Week

Hot Threads This Month