简体   繁体   中英

mod_rewrite doesnt work if file with same name as argument exists

I'm experiencing some issues with mod_rewrite in htaccess.

Let's for instance say I request example.com/foo/, it works perfectly if I don't have a file starting with "foo.*" in the root directory.

Let's say I have news.php, sitemape.xml, style.css in root, I can't use /news/ or /sitemap/ or /style/ , it will give a 404 like /news.php/ etc.

Here's my rewrite string. It works locally with my Apache 2.2.22 but not at my web-host with the same Apache version.

RewriteRule ^([A-Za-z0-9]+)/?$ index.php?category=$1 [NC,L]

Anyone has a clue?

This sounds like Multiviews rearing its ugly head when its not wanted. It may be that your host automatically turns on the Multiviews option by default, and mod_negotiation then tries to "guess" what the request is for, and if it's close enough (like with /news/ and /news.php ), it will automatically serve it, and disregard whatever mod_rewrite rules you may have.

Try turning off multiviews. You can do this in your htaccess file using the Options directive (assuming your host has allowed Options):

Options -Multiviews

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