You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@httpd.apache.org by Andrea Rossignoli <ap...@libero.it> on 2003/09/12 09:26:10 UTC

REQUEST_FILENAME usage in mod_rewrite 1.3 doc

Hi,
in my opinion some examples from 
http://httpd.apache.org/docs/misc/rewriteguide.html are not correct.

In particular I'm talking about of some usages of %{REQUEST_FILENAME}.

 From the link I posted you can find:

***********example 1, start...
Search pages in more than one directory

RewriteEngine on

#   first try to find it in custom/...
#   ...and if found stop and be happy:
RewriteCond         /your/docroot/dir1/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.+)  /your/docroot/dir1/$1  [L]

#   second try to find it in pub/...
#   ...and if found stop and be happy:
RewriteCond         /your/docroot/dir2/%{REQUEST_FILENAME}  -f
RewriteRule  ^(.+)  /your/docroot/dir2/$1  [L]

#   else go on for other Alias or ScriptAlias directives,
#   etc.
RewriteRule   ^(.+)  -  [PT]
***********...example 1, end

***********example 2, start...
Redirect Failing URLs To Other Webserver

RewriteEngine on
RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
RewriteRule   ^(.+)                             http://webserverB.dom/$1
***********...example 2, end

In these examples you will see the usage of

/your/docroot/%{REQUEST_FILENAME}
/your/docroot/dir1/%{REQUEST_FILENAME}
/your/docroot/dir2/%{REQUEST_FILENAME}


That's not correct.
Suppose the DocumentRoot is /your/docroot

for a request as www.example.com/myfile.php
%{REQUEST_FILENAME} will be /your/docroot/myfile.php

for a request as www.example.com/path/to/myfile.php
%{REQUEST_FILENAME} will be /your/docroot/path/to/myfile.php

Using
RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
means like
RewriteCond   /your/docroot//your/docroot/myfile.php !-f
or
RewriteCond   /your/docroot//your/docroot/path/to/myfile.php !-f

and that's not correct.


I can illustrate what I said using my log file.
I used these rules:

         RewriteEngine on
         RewriteCond   /usr/www/example.net/htdocs/%{REQUEST_FILENAME} !-f
         RewriteRule   ^(.+) http://example.com/$1

my DocumentRoot was "/usr/www/example.net/htdocs"

I requested: www.example.net/plata.php

etc (3) [per-dir /usr/www/example.net/htdocs/] strip per-dir prefix: 
/usr/www/example.net/htdocs/plata.php -> plata.php
etc (3) [per-dir /usr/www/example.net/htdocs/] applying pattern '^(.+)' 
to uri 'plata.php'
etc (4) RewriteCond: 
input='/usr/www/example.net/htdocs//usr/www/example.net/htdocs/plata.php' 
pattern='!-f' => matched
etc (2) [per-dir /usr/www/example.net/htdocs/] rewrite plata.php -> 
http://example.com/plata.php
etc (2) [per-dir /usr/www/example.net/htdocs/] implicitly forcing 
redirect (rc=302) with http://example.com/plata.php
etc (1) [per-dir /usr/www/example.net/htdocs/] escaping 
http://example.com/plata.php for redirect
etc (1) [per-dir /usr/www/example.net/htdocs/] redirect to 
http://example.com/plata.php [REDIRECT/302]

check (4) -->> 
input='/usr/www/example.net/htdocs//usr/www/example.net/htdocs/plata.php'

So summing instead of
/your/docroot/%{REQUEST_FILENAME}
/your/docroot/dir1/%{REQUEST_FILENAME}
/your/docroot/dir2/%{REQUEST_FILENAME}
it was more correct to use
%{REQUEST_FILENAME}
for all the examples I showed.

What do you think ?


Thank you,
Mr Andrea Rossignoli

p.s.
Hope this is the correct mailing list... :-)


---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org


Re: REQUEST_FILENAME usage in mod_rewrite 1.3 doc

Posted by André Malo <nd...@perlig.de>.
* Andrea Rossignoli wrote:

> in my opinion some examples from
> http://httpd.apache.org/docs/misc/rewriteguide.html are not correct.

<snip>
> etc (3) [per-dir /usr/www/example.net/htdocs/] strip per-dir prefix:
           ^^^^^^^

That is the point. The rewriterules there are supposed to work in server context
(as said above all the examples). But agreed in general, the rewriteguide is
not sufficient any longer, because mod_rewrite usage in .htaccess files became
very popular in the meantime.

> Hope this is the correct mailing list... :-)

Yes :)

nd

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org