[英]Avoid apache to match filename in uris
I have a litle app written in php, using apache. 我有一个使用Apache用php编写的小应用程序。 I have wrote the following in my .htaccess
我在.htaccess
写了以下内容
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,NC,L]
</IfModule>
So, basically I want to handle all uris in my index.php file. 因此,基本上,我想处理index.php文件中的所有uri。 It's working almost fine, my problem is when I try to match an uri and there is a .php
file with that name, for example if I have an api.php
file, then the uri http://localhost/app-name/api
throws an 404 error
它几乎可以正常工作,我的问题是当我尝试匹配uri时,并且有一个具有该名称的.php
文件,例如,如果我有api.php
文件,那么uri http://localhost/app-name/api
引发404 error
So, how can I handle all uris with index.php
? 因此,如何使用index.php
处理所有uri? why isn't the directive RewriteRule ^(.*)$ index.php/$1 [QSA,NC,L]
working properly? 为什么指令RewriteRule ^(.*)$ index.php/$1 [QSA,NC,L]
正常工作?
Try updating your code and turning off multiviews
. 尝试更新代码并关闭multiviews
。 It by default looks for files with an extension with the same name as you put in. 默认情况下,它将查找带有与您输入的名称相同的扩展名的文件。
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,NC,L]
</IfModule>
Side note, I've never seen anyone who actually wanted to use this feature. 旁注,我从未见过真正想要使用此功能的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.