如果存在与参数名称相同的文件,则mod_rewrite不起作用 [英] mod_rewrite doesnt work if file with same name as argument exists

查看:37
本文介绍了如果存在与参数名称相同的文件,则mod_rewrite不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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]

有人知道吗?

推荐答案

这听起来像/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不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆