如何prevent阿帕奇/ mod_rewrite对治疗路径,文件名称相同 [英] How to prevent Apache / mod_rewrite from treating path as file with same name

查看:112
本文介绍了如何prevent阿帕奇/ mod_rewrite对治疗路径,文件名称相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WAMP的服务器,主要配置为,是开箱。我遇到了麻烦mod_rewrite的表现如预期本地(一切正常在生产服务器上)。

I'm using WAMP Server, mostly configured as-is out of the box. I'm having trouble getting mod_rewrite to behave as expected locally (everything works fine on a production server).

我有位于一个PHP文件: /ajax/graphs/get-graph.php

I have a PHP file located at: /ajax/graphs/get-graph.php

这个文件通常调用的方式是通过由加载的引导文件 的index.php

The way this file is normally invoked is via a bootstrap file loaded by /index.php

我在根目录下的.htaccess文件以下规则:

I have a .htaccess file at the root with the following rules:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L]

所以,基本上,当通过AJAX我的应用程序的请求调用 /阿贾克斯/图表/ GET-图/ 应该指向 /的index.php

现在的问题是,阿帕奇/ mod_rewrite的看到 /ajax/graphs/get-graph.php 直接请求路径和负载。

The problem is, Apache/mod_rewrite sees the request path and loads /ajax/graphs/get-graph.php directly.

我如何prevent阿帕奇从假设 /阿贾克斯/图表/ GET-图/ 是一个有效的文件,因为同名的php文件存在于该位置?

How do I prevent Apache from assuming that /ajax/graphs/get-graph/ is a valid file because a php file of the same name exists at that location?

推荐答案

这听起来像你已经陷入了内容协商的陷阱;-)作为的 Apache文档,有一个名为选项多视​​图其中,当启用,导致Apache基本转换不存在的目录名到其对应的文件名。

It sounds like you've fallen into the trap of content negotiation ;-) As explained in the Apache documentation, there is an option called MultiViews which, when enabled, causes Apache to basically convert nonexistent directory names into their corresponding filenames.

多视图的效果如下:如果服务器收到一个请求 /一些/ DIR /富,如果 /一些/目录已启用了多视图,而 /一些/ DIR /富不存在,则服务器读取目录中寻找一个名为文件富。* ,并有效假货一个类型的地图,名称的所有文件...

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files...

这样做的目的是,你可以有几个版本的不同格式或者语言,文件像

The intent is that you can have several versions of a file in different formats or languages, like

/some/dir
- foo.en.gif
- foo.en.png
- foo.en.jpg
- foo.fr.gif
- foo.fr.png
- foo.fr.jpg

和Apache会根据浏览器提供的preferences选择最好的之一。

and Apache will choose the best one based on the preferences provided by the browser.

要解决这个问题,你应该需要做的就是添加指令

To fix it, all you should need to do is add the directive

Options -MultiViews

<目录> <地点> 相应块 / AJAX /图。或者,如果你没有访问主服务器配置,你可以把它放在 /ajax/graphs/.htaccess

in a <Directory> or <Location> block corresponding to /ajax/graphs. Or, if you don't have access to the main server configuration, you can put it in /ajax/graphs/.htaccess.

这篇关于如何prevent阿帕奇/ mod_rewrite对治疗路径,文件名称相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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