You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Louis-David Mitterrand <cu...@apartia.ch> on 2000/07/23 20:09:55 UTC

[OT] strange mod_rewrite behaviour (for Apache::Session support)

Hello,

I am in the process of implementing persistent sessions using
Apache::Session with the session_id stored in the URL and it mostly
works. In the HTML::Mason autohandler there is the following filter:

<%filter>
$r->pnotes("cookie") # mangle URL only if cookie is missing
	|| s#\bhref\s*=\s*"(/(?!S=)[^"\s]*)"#href="/S=$session{_session_id}$1"#gi;
</%filter>

... which adds the session_id to all href links, only if the browser
doesn't return any cookie.

Now in httpd.conf there is a mod_rewrite rule inspired by a recent
thread on the modperl list:

RewriteRule ^/S=([^/]+)(/.*) $2 [E=AF_SID:$1]

This removes the session_id from the URL and adds it to the AF_SID
environment variable. This works well for all absolute URLs (starting
with a /) which is puzzling because I remember reading in this thread
that this technique mandated _relative_ URLs.

The rewrite rule fails only in one case, the root URL:

http://my.site.com/S=1d2e580af1e31cf2/Sell/index.html

... is correctly converted to 

http://my.site.com/Sell/index.html

... *but*

http://my.site.com/S=1d2e580af1e31cf2/

... fails with a 404 NOT FOUND error