homepage Welcome to WebmasterWorld Guest from 54.196.194.204
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Mod rewrite and cookies
Has anyone got mod rewrite to act on cookies?
theperlyking




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

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.
Thanks.

 

DaveAtIFG




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

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...

Air




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

>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.

theperlyking




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

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.

Air




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

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]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved