简体   繁体   中英

htaccess rewrite rule without access to direct file

I have this in my .htaccess file:

RewriteEngine on

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

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

This works fine. eg when entering localhost/file it acts as if it was localhost/index.php?route=file

My problem however is that the server is set to serve files without the need to type .php as file extension. So when I access localhost/login , instead of doing localhost/index.php?route=login , it serves me the file login.php directly. How can I avoid that?

Simply disable MultiViews option.

Replace your current code by this one

Options -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

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