You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Shyne <ch...@shyne.ch> on 2006/02/20 02:52:15 UTC

[users@httpd] mod_rewrite directives problem

Hello

I want to do the following:
- in the directory /help/ forward all requests for non-existing 
documents or folders to a script which is in the same folder, but leave 
access to existing documents and folders in /help/ untouched
- the phrase the user entered - something like 
www.mydomain.org/help/Hallo Welt - should be passed as an argument to 
the script
- the user should not see, that he/she is being forwarded

Problem:
- existing documents get forwarded
- non existing documents produce a 404
- a simple ErrorDoument 404 /help/index.php won't do, because the user 
should not see that he/she is getting forwarded

Here are the directives:

<VirtualHost *:80>
...

    RewriteEngine on
    RewriteCond /help/%(REQUEST_URI) !-d
    RewriteCond /help/%(REQUEST_URI) !-f

    RewriteRule ^help/?(.*)$ /help/index.php?id=$1 [L,QSA]

</VirtualHost>


- I am not sure if /help/%(REQUEST_URI) points to the right place, but 
RewriteBase is not permitted in VirtualHost directives
- Should it be ^help/ or ^/help/
...

Does somebody have an idea, how to solve this?
Thank you and greetings,
Carole.


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


Re: [users@httpd] mod_rewrite directives problem

Posted by Robert Ionescu <ro...@googlemail.com>.
Joost de Heer wrote:
> Robert Ionescu wrote:
>> Shyne wrote:
>>> Apparently the directive RewriteCond %{REQUEST_FILENAME} !-f matches
>>> requests for existing files, which it should exactly not do.
>> We were able to analyze the RewriteLog in a German mod_rewrite forum.
>> The problem here was the following:
>>
>> %{REQUEST_FILENAME} did contain the value from %{REQUEST_URI}, namely
>> /help/abc but not the expected and needed full physical path
>> /var/www/help/abc.
> 
> Sounds like you're using rewrites in a .htaccess file. That results in
> directories at the beginning being chopped off.

No, the rules were placed in the virtualhost section, per-server context.

I have never heard that ENVs are choped off in per-dir context, only the 
pattern of the RewriteRule is a filepath there (while a local URL in 
per-server context) which changes from the point where the .htaccess is 
placed (striped per-dir prefix).
But the "problem" here is not the rule-pattern but the value of the ENV 
%{REQUEST_FILENAME} where (in per-server context) the filename field of 
request_rec contains the same value as the uri field does.

I think this is a logical behavior, because afaik the filename 
translation comes in a later step of processing, so the full physical 
path is simply not known in this step of processing.

I found also an assigned docs bug report from January 2003:
http://issues.apache.org/bugzilla/show_bug.cgi?id=16402 but obviously it 
is not fixed yet.

At least the "average user" cannot read between the lines

| the value of the filename field of the internal request_rec structure
| of the Apache server.
| (http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond ,
| "Other things you should be aware of:")

that filename does not (cannot) contain the full physical path in 
per-server context (if you don't perform an url-based sub-request lookup).

-- 
Robert

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


Re: [users@httpd] mod_rewrite directives problem

Posted by Joost de Heer <sa...@xs4all.nl>.
Robert Ionescu wrote:
> Shyne wrote:
>> Apparently the directive RewriteCond %{REQUEST_FILENAME} !-f matches
>> requests for existing files, which it should exactly not do.
>
> We were able to analyze the RewriteLog in a German mod_rewrite forum.
> The problem here was the following:
>
> %{REQUEST_FILENAME} did contain the value from %{REQUEST_URI}, namely
> /help/abc but not the expected and needed full physical path
> /var/www/help/abc.

Sounds like you're using rewrites in a .htaccess file. That results in
directories at the beginning being chopped off.

Joost


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


Re: [users@httpd] mod_rewrite directives problem

Posted by Robert Ionescu <ro...@googlemail.com>.
Shyne wrote:
> Apparently the directive RewriteCond %{REQUEST_FILENAME} !-f matches 
> requests for existing files, which it should exactly not do.

We were able to analyze the RewriteLog in a German mod_rewrite forum. 
The problem here was the following:

%{REQUEST_FILENAME} did contain the value from %{REQUEST_URI}, namely
/help/abc but not the expected and needed full physical path 
/var/www/help/abc.

An URL-based sub-request (LA:U) was able to determine the correct value.

-- 
Robert

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


Re: [users@httpd] mod_rewrite directives problem

Posted by Shyne <ch...@shyne.ch>.
Hi Robert

Thanks for your answer.

I changed the directives according to your input and installed the log.

Apparently the directive RewriteCond %{REQUEST_FILENAME} !-f matches 
requests for existing files, which it should exactly not do.
I try to filter out all requests for non existing documents and folders 
and lead them to my script, but leave the existing stuff untouched.

Is there a different way to do the filtering for non existing documents 
(with leaving what has been entered in the Address Bar unchanged)?

Thanks and greetings,
Carole.


Robert Ionescu wrote:
> Shyne wrote:
>> <VirtualHost *:80>
>> ...
>>
>>    RewriteEngine on
>>    RewriteCond /help/%(REQUEST_URI) !-d
>>    RewriteCond /help/%(REQUEST_URI) !-f
>>
>>    RewriteRule ^help/?(.*)$ /help/index.php?id=$1 [L,QSA]
>>
>> </VirtualHost>
>>
>>
>> - I am not sure if /help/%(REQUEST_URI) points to the right place, but 
>
> Round parenthesis are wrong, you must use {...}, but consider using
>
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !-f
>
>> - Should it be ^help/ or ^/help/
>
> In per-server context: ^/help/
>
> In order to debug RewriteRules, use a RewriteLog
>
> RewriteLog logs/rewrite
> Rewriteloglevel 5
>


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


Re: [users@httpd] mod_rewrite directives problem

Posted by Robert Ionescu <ro...@googlemail.com>.
Shyne wrote:
> <VirtualHost *:80>
> ...
> 
>    RewriteEngine on
>    RewriteCond /help/%(REQUEST_URI) !-d
>    RewriteCond /help/%(REQUEST_URI) !-f
> 
>    RewriteRule ^help/?(.*)$ /help/index.php?id=$1 [L,QSA]
> 
> </VirtualHost>
> 
> 
> - I am not sure if /help/%(REQUEST_URI) points to the right place, but 

Round parenthesis are wrong, you must use {...}, but consider using

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

> - Should it be ^help/ or ^/help/

In per-server context: ^/help/

In order to debug RewriteRules, use a RewriteLog

RewriteLog logs/rewrite
Rewriteloglevel 5

-- 
Robert

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