mod_rewrite doesnt work if file with same name as argument exists

时间秒杀一切 提交于 2020-01-05 05:25:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!