[英]htaccess rewrite rule without access to direct file
I have this in my .htaccess
file: 我的.htaccess
文件中有此文件:
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
例如,当输入localhost/file
它的行为就好像是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. 但是我的问题是服务器设置为提供文件,而无需键入.php
作为文件扩展名。 So when I access localhost/login
, instead of doing localhost/index.php?route=login
, it serves me the file login.php
directly. 因此,当我访问localhost/login
,而不是执行localhost/index.php?route=login
,它将直接为我提供文件login.php
。 How can I avoid that? 我该如何避免呢?
Simply disable MultiViews
option. 只需禁用MultiViews
选项。
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.