You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Alan Little <da...@holotech.net> on 2006/03/09 19:11:00 UTC

Re[2]: [users@httpd] Cookie-Based Rewrite

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:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org