简体   繁体   中英

mod_rewrite redirects to .html in error

I've just setup an AMP server on OSX 10.9 and have a bizzare problem which is not present on my live hosting server or my old WAMP server.

I want to redirect any URL that doesn't directly map to a file on the server to index.php. I'm using the following .htaccess code

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# prevent loop
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*)$ /index.php?/$1 [L]

when I try http://example.com/example there is no problem, but when I introduce another slash, for example, http://example.com/example/

I get the a 404 error The requested URL /example.html/ was not found on this server.

Server version: Apache/2.2.26 (Unix)

Looks like your problem is related to enabling of MultiViews here. Turn it off by using this line on top of your .htaccess:

Options -MultiViews
  • Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM