问题描述
我在htaccess中遇到了mod_rewrite的一些问题.
I'm experiencing some issues with mod_rewrite in htaccess.
例如,假设我请求example.com/foo/,如果我在根目录中没有以"foo.*"开头的文件,则该方法可以完美地工作.
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.
比方说,我的根目录中有news.php,sitemape.xml,style.css,我不能使用/news/或/sitemap/或/style/,它会给出404像/news.php/等
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.
这是我的重写字符串.它可以在本地使用我的Apache 2.2.22,但不能在具有相同Apache版本的Web主机上使用.
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]
有人知道吗?
推荐答案
这听起来像多视图在不需要时抬起丑陋的头.可能是您的主机默认情况下自动打开了Multiviews
选项,然后mod_negotiation尝试猜测"请求的内容,如果请求足够接近(例如使用/news/
和/news.php
),它将自动提供服务,而忽略您可能具有的任何mod_rewrite规则.
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.
尝试关闭多视图.您可以使用 Options
在htaccess文件中执行此操作指令(假设您的主机允许使用选项):
Try turning off multiviews. You can do this in your htaccess file using the Options
directive (assuming your host has allowed Options):
Options -Multiviews
这篇关于如果存在与参数名称相同的文件,则mod_rewrite不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!