简体   繁体   English

如果存在与参数同名的文件,则mod_rewrite不起作用

[英]mod_rewrite doesnt work if file with same name as argument exists

I'm experiencing some issues with mod_rewrite in htaccess. 我在htaccess中遇到了mod_rewrite的一些问题。

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. 例如,假设我请求example.com/foo/,如果我在根目录中没有以“foo。*”开头的文件,则它可以正常工作。

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. 假设我在root中有news.php,sitemape.xml,style.css,我不能使用/ news /或/ sitemap /或/ style /,它会给出像/news.php/这样的404。

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. 它在我的Apache 2.2.22本地工作,但在我的web主机上没有相同的Apache版本。

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. 这听起来就像是Multiviews在不想要它的情况下养成它丑陋的脑袋。 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. 可能是您的主机默认情况下自动打开Multiviews选项,然后mod_negotiation会尝试“猜测”请求的内容,如果它足够接近(例如/news//news.php ),它会自动服务它,并忽略你可能有的任何mod_rewrite规则。

Try turning off multiviews. 尝试关闭多视图。 You can do this in your htaccess file using the Options directive (assuming your host has allowed Options): 您可以使用Options指令在htaccess文件中执行此Options (假设您的主机已允许选项):

Options -Multiviews

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM