unexpected/bogus behavior of RedirectMatch/mod_rewrite

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Consider the following httpd.conf file:

    ServerName localhost:80
    Listen 127.0.0.1:80
    DocumentRoot "/var/www/html"
    DirectoryIndex index.html

There's a /var/www/html/index.html file that contains a simple test message.

Now, say that (for whatever reason) we want to redirect all requests
for any URL-path except / (root) to the root.

You should be able to do that with a RedirectMatch:

    RedirectMatch permanent ^/.+$ http://localhost/

Or you could do it using mod_rewrite:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/$
    RewriteRule .* http://localhost/ [redirect=permanent,last]

But either approach will, in fact, fail: *all* URL-paths will return a
redirect to the root, including the root itself.

If you enable RewriteLog and crank up the RewriteLogLevel, you can see
what is happening:

127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#555556458dd8/initial] (2) init rewrite engine with requested uri /
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#555556458dd8/initial] (3) applying pattern '.*' to uri '/'
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#555556458dd8/initial] (1) pass through /
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#55555645ee08/subreq] (2) init rewrite engine with requested uri /index.html
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#55555645ee08/subreq] (1) pass through /index.html
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#555556465f48/initial/redir#1] (2) init rewrite engine with requested uri /index.html
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#555556465f48/initial/redir#1] (3) applying pattern '.*' to uri '/index.html'
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#555556465f48/initial/redir#1] (2) rewrite '/index.html' -> 'http://localhost/'
127.0.0.1 - - [05/Sep/2007:19:21:44 --0400] [localhost/sid#5555557b2d30][rid#555556465f48/initial/redir#1] (2) explicitly forcing redirect with http://localhost/

In English, this means that although / is properly excluded from the
rewrite, when httpd finds index.html (via the DirectoryIndex
directive), and logically "applies" it to the client's request, the
result is also subject to being written via RedirectMatch/mod_rewrite,
even though the client never included "index.html" in the original
URL-path.

I think this is either a bug with the server, or a bug with the
documentation.  The documentation for RedirectMatch and mod_rewrite
are both explicitly clear that the match is against the URL-path,
which is defined in "Terms Used to Describe Directives" as:

    URL-path:

    The part of a url which follows the scheme and hostname as in
    /path/to/file.html. The url-path represents a web-view of a
    resource, as opposed to a file-system view.

But this is not the behavior of RedirectMatch/mod_rewrite; they are in
fact matching not just the URL-path, but a quasi-expansion of the
client's request that is somewhere in between URL-path and file-path.
(I've tested both httpd 2.0 and 2.2; they both exhibit this behavior.)

If that's the intended behavior, then the documentation is wrong; if
that's not the intended behavior, then this is a bug with the server.

Comments?

(If I receive no dissuading comments within a few days, I'll file this
as a bug via Bugzilla.)

Thanks...


---------------------------------------------------------------------
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@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux