[thelist] Re: Apache mod_rewrite and PHP SID
Tony Light
TonyLight at blueyonder.co.uk
Thu Feb 6 05:53:35 CST 2003
Problem solved - thanks to some digging in the Apache docs.
Answer: Many server variables are available to you when creating
RewriteRules for mod_rewrite.
The query string is one of them.
So to ensure that any query string that may be present is passed on in the
rewritten url, append it as follows:
RewriteRule ^/([0-9])/?$
/play/modrewrite/echo.php?id=$1&%{QUERY_STRING}
If I was concerned about the content of %{QUERY_STRING}, then I could check
it in a RewriteCond immediately before the RewriteRule.
e.g.
RewriteCond %{QUERY_STRING} ^(|PHPSESSID=([0-9a-f]){32})$
... would mean that the RewriteRule would only take place if the query
string did not exist at all, or was exactly of the format "PHPSESSID=" plus
a 32 char session id.
Hope this helps someone.
Thanks to all who gave their time to reply.
Cheers,
Tony.
> Original problem:
> <><><><><><><><><><><><><><><><><><><><><><>
> > 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.
> <><><><><><><><><><><><><><><><><><><><><><>
More information about the thelist
mailing list