开发者

mod_rewrite problem: RewriteCond %{REQUEST_FILENAME} !-f matches even when REQUEST_FILENAME shouldn't (fully) match

开发者 https://www.devze.com 2023-04-03 04:33 出处:网络
For some reason this rule RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ./rewrite.php?p=$1&%{QUERY_STRING} [L]

For some reason this rule

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./rewrite.php?p=$1&%{QUERY_STRING} [L]

doesn't work for URLs like this http://site.com/index/var/val

All other URLs work but this doesn't. It starts working when I either remove !-f part or rename index.php file located in the root to something else (e.g. test.php). So somehow site.com/index seems to be equal to site.com/index.php in the eyes of mod_rewrite? The files are located in the root so there shouldn't be any other (upper)开发者_Python百科 .htaccess files involved. This doesn't happen to index only, for example if I create /something.xml, test.com/something/... will suddenly stop working. This happens on some servers only.

Does anyone know why this could be happening?

PS. /index directory is not present on this server


The faulty module is mod_negotiation, not mod_rewrite.

In debian :

a2dismod negotiation

Edit:

To be a little more specific this is the effect of Multiviews, handled by mode_negotiation. So you could keep the module and remove the MultiViews handling with:

Options -MultiViews

From documentation:

A MultiViews search is enabled by the MultiViews Options. If the server receives a request for /some/dir/foo and /some/dir/foo does not exist, then the server reads the directory looking for all files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements, and returns that document.


I've also solved this problem by removing the MultiViews keyword from the

<Directory>

section from my server configuration.

Hope this helps.

I believe the ${REQUEST_FILENAME} aproaches the file as if it was served to a browser directly.

I had a similar problem with this:

  • /content/detailed-page (Rewritten URL and parsed by php)

The file was returned to me the same way as:

  • /content/detailed-page.html (real file)
0

精彩评论

暂无评论...
验证码 换一张
取 消