简体   繁体   中英

Avoid apache to match filename in uris

I have a litle app written in php, using apache. I have wrote the following in my .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. 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

So, how can I handle all uris with index.php ? why isn't the directive RewriteRule ^(.*)$ index.php/$1 [QSA,NC,L] working properly?

Try updating your code and turning off 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.

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