[thelist] Apache mod_rewrite and PHP SID

Tony Light TonyLight at blueyonder.co.uk
Wed Feb 5 04:46:01 CST 2003


--
[ Picked text/plain from multipart/alternative ]
I'm experimenting with Apache's mod_rewrite (in order to make my sites more search engine friendly).

First experiment used the following rule...
RewriteRule ^/([0-9])/?$                /play/modrewrite/echo.php?id=$1

This takes urls of the form www.mydomain.com/n (where n is a single digit numeric - and with or without trailing slash) and calls /play/modrewrite/echo.php with ?id=n appended.

All hunky dory.

Now the question....
How can I deal with a query string appended after the url?

e.g. www.mydomain.com/n?extrainfo=something

Such a url will still be intercepted by the RewriteRule above, and 'redirected' to /play/modrewrite/echo.php.
However - the query string (even though it appears in the browser address bar) is ignored.

You are probably asking yourself WHY does this twit go to the trouble of using mod_rewrite, and still want to stick a query string on the end?

Well, I use PHP sessions.  If the user has Cookies totally switched off, then sessions will not work unless you pass the special SID variable around appended to all your internal links.

e.g. <a href="http://www.mydomain.com/1?<?php echo(SID)?>">

which after PHP parsing comes out something like:
<a href="http://www.mydomain.com/1?"> .... if cookies are enabled
<a href="http://www.mydomain.com/1?PHPSESSID=abcdefgh123456789"> .... if cookies are not enabled.

Has anybody encountered (and solved) this already?
I would hate to have to demand that Cookies were enabled, just so I could keep a session going.

Cheers,
    Tony.

--




More information about the thelist mailing list