Installa la nostra toolbar!
Tips / Apache
addthis
Apache auto appends extensions to files
Author: Tafaz
Visits: 1855
Date: 15.11.2008

In the past days I stumbled in this Apache's "strange" behavior (not so strange as we'll see after). In few words I was codimng a website with url rewriting when i found that if I call an URL with the name of an existing file but without extension Apache automatically add the extension without doinbg the rewrite.

The rewrite was structured as below:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} !(\.php)
RewriteRule (.*) index.php?r=$1&%{QUERY_STRING}

shortly these rules rewrites every call that point to non existing files or directories to the file index.php passing as parameter r the requested path and appending the query string. This way avoids me to write lots of rewrite rules leaving the hard work to index.php. The problem happens when I request an URL like http://mysite.com/info/ and in the root of mysite.com I have a file called info.php, info.html, etc apache instead of rewriting the URL to index.php show me the file info.php.

After some hours of struggling searching in apache's modules I've found that is the option MultiViews that tells apache to do this, infact if is requested a path like /some/dir/foo and file foo doesn't exist and /some/dir has MultiViews enabled apache will search for files named foo.* serving the first if found.

MultiViews is a per-directory option and can be modified by both form apache configuration file and .htaccess simply putting -MultiViews in one of the following sections <Directory>, <Location> or <Files>.

so I've added the bolded line
<Directory /var/www>
       Options -MultiViews
</Directory>
restarted apache and now everything works fine!


Page 1 of 1


Se vuoi discutere con noi su questo articolo o comunque vuoi porci delle domande usa il nostro Forum

COMMENTI

Aggiungi un commento! +
(I commenti verranno moderati prima della pubblicazione)



Top