httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joshua Slive" <>
Subject Re: [users@httpd] Mod_rewrite and default document
Date Thu, 14 Sep 2006 13:28:33 GMT
On 9/13/06, Erik Funkenbusch <> wrote:
> > > See my problem?  I have to match a root page request with a query
> > > string of ?id=[anything]
> >
> > There's an excellent book about regular expressions from O'Reilly. Spend a
> > weekend with it, really.
> *sigh*. Do we really need the condescending tone?  Especially since
> your example doesn't work either Mr. Expert.
> This is not a simple problem.  I've tried hundreds of different
> patterns, read dozens of different web pages, and yes, I've read
> Mastering Regular Expressions.
> > RewriteEngine on
> > # this rule will match all url's starting with index.php,
> > # including /index.php?foo=bar but also /index.phpxxx
> > RewriteRule /index.php(.*)$ /index.php$1 [L]
> > # if that rule isn't matched, the follwing rule will ut anything as id=
> > RewriteRule ^(.*)$ /index.php?id=$1 [L]
> >
> > Would that help !?
> No, it doesn't, because it doesn't match the url:
> http://mydomain/?id=abc123
> As far as I can tell, mod_rewrite doesn't work the way you think it
> does.  The default document gets interpreted AFTER mod_rewrite
> processes the URL.  I could be wrong about that, but that's what it
> seems to be doing.
> There seems to be some cryptic interaction between mod_rewrite and
> apache in terms of what order it processes things.

What is missing is the special handling of the query string described
in the box "Note: Query String" under here:

You could probably use something like
RewriteCond %{QUERY_STRING} ^id=.*$
RewriteRule !/index\.php /index.php [QSA,L]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule (.*) /index.php?id=$1 [L]

And given the first set of rules duplicates what mod_dir will already
be doing, you might even be able to get away with just
RewriteCond %{QUERY_STRING} !^id=
RewriteRule (.*) /index.php?id=$1 [L]

Use the RewriteLog for further debugging.


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