问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/17383889/mod-rewrite-doesnt-work-if-file-with-same-name-as-argument-exists