httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Little <>
Subject Re[2]: [users@httpd] Cookie-Based Rewrite
Date Thu, 09 Mar 2006 18:11:00 GMT
Thank you. Unfortunately, this is on a shared hosting server, and I
don't have access to the config files, nor the re-write log (if there
is one).

I figured out after I posted my question that I needed to exclude the
/demo/ directory, since that's where this is. I tried the regex you
suggested -- it makes more sense. But I still get the error. If I add
the RewriteCond for REQUEST_URI, I no longer get the error, but no
rewrite, either.

I must say, most of what I do with mod_rewrite is MSMD. I don't really
understand how it works, except in the most general terms. It would be
great if there was something that explained what exactly mod_rewrite
does, step by step, but all the tutorials I've been able to find are
really just recipes for doing various things, without really
explaining what's going on.

From what I understand, the rule as you wrote it goes:

> RewriteCond %{REQUEST_URI} !^/demo/

"If REQUEST_URI does not begin with /demo/"

> RewriteCond %{HTTP_COOKIE} phn_demo=([^;]+)

"...and HTTP_COOKIE contains 'phn_demo=' followed by a value"

> RewriteRule ^(.*) /%1/$1 [L]

"...rewrite the request to point to directory %1 (the value from
RewriteCond) below this directory, followed by whatever's left of
the URI."

Isn't that correct? It seems pretty straightforward to me, but for
some reason doesn't work.

Alan Little
Holotech Enterprises

On Thursday, March 9, 2006, 11:38:34 AM, you wrote:

> Alan Little wrote:
>> I have a rule in
>> doc root for the domain

> Why don't you use the Rules in per-server context (httpd.conf), many 
> things are a lot easier there, because there is no internal redirect and
> the regEx is only compiled once at startup and not per each request.

> What can you find in your rewrite.log? Or are the rules not processed?

>>   RewriteCond %{HTTP_COOKIE} phn_demo=(.*)
>>   RewriteRule (.*) /demo/%1/$1

> If you're using the rule in per-dir context, you must exclude the folder
> /demo/ as you did for the other rule. May be you must separate the group
> from other cookies, too?

> RewriteEngine on
> RewriteCond %{REQUEST_URI} !^/demo/
> RewriteCond %{HTTP_COOKIE} phn_demo=([^;]+)
> RewriteRule ^(.*) /demo/%1/$1 [L]

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message