Apache 404 Error When ‘index’ is in the Path

apache-2.2httpmod-rewriteshared-hosting

I have a long standing problem with mod_rewrite and 1and1 shared hosting (hope that being shared hosting does't get this migrated to 'sharedserverfault'). Everything about the rewrite rules work fine – except when 'index' is in the path. Then I get an Apache 404 error.

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

Pretty standard so far, works fine on most server. On 1and1's server I get a 404 error if index is the top 'directory'. Anything starting with 'http://example.com/index' will give a 404.

If I copy index.php to bootstrap.php and change the .htaccess file to point there and delete index.php, it will work.

However, that makes it a pain to update the server – any ideas what apache settings are causing this? Obviously I can't change the main configuration file, but I can override settings with the .htaccess file.

Best Answer

Found the answer here:

After some digging around, the solution is to disable something called MultiViews. The MultiViews option allows a file to be called even if the extension is not loaded, so index would look for any files called index, regardless of their extension.

So the solution is to add:

Options -MultiViews

to the .htaccess file.

Related Topic