如何阻止Apache从URLpath中find文件名(没有扩展名)

我在我的文档根目录中有一个文件update.php

但我不希望/update我的URL直接到update.php(因为我想/update与我的CMS,Drupal 7中的页面相关联)

我知道在Drupal看到Apache之前,Apache正在“处理” /update :我在我的本地开发器上创build了一个新的空文件夹test.dev,在其中放置一个名为orange.html的文件,并且我的浏览器访问了test.dev/orange显示orange.html – 所以这是configurationApache的情况

我的configuration是从puphpet.com Ubuntu12.04 PHP5.5最默认提供的设置

  test.conf # ************************************ # Vhost template in module puppetlabs-apache # Managed by Puppet # ************************************ <VirtualHost *:80> ServerName test.dev ## Vhost docroot DocumentRoot "/var/www/test.dev" ## Directories, there should at least be a declaration for /var/www/test.dev <Directory "/var/www/test.dev"> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> ## Load additional static includes ## Logging ErrorLog "/var/log/apache2/test_error.log" ServerSignature Off CustomLog "/var/log/apache2/test_access.log" combined ## SetEnv/SetEnvIf for environment variables SetEnv APP_ENV dev ## Custom fragment </VirtualHost> 

我如何configurationApache,以便id不会尝试获取名称(不带扩展名)与URL匹配的文件? 我很乐意为特定的情况做/update我宁愿不要closures当前的configuration,以防万一它干净的URL地址(回归)的东西。 我宁愿为/update 添加特定的“exception”情况。

我的设置:Ubuntu 12.04 LTS

 apache2 -v Server version: Apache/2.4.9 (Ubuntu) Server built: Apr 1 2014 08:52:12 

虚拟机是build立与皮肤清单: https : //github.com/therobyouknow/VagrantVMSetups/tree/20140721_puphpet_U1204_php55

根本原因是MultiViews指令

http://httpd.apache.org/docs/2.4/mod/mod_negotiation.html#multiviews

如果服务器收到/ some / dir / foo的请求并且/ some / dir / foo不存在,那么服务器将读取目录,查找所有名为foo。*的文件,并有效地伪造一个名为all文件,为它们分配相同的媒体types和内容编码,如果客户要求其名称中的一个,将会有这种编码。 然后select与客户要求最匹配的,并返回该文件。

在我的网站的conf文件中,我从下面删除了MultiViews

 <Directory "/var/www/test.dev/public_html"> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> 

并重新启动Apache

我发现我从Drupal中得到了'page not found'页面 – 这正是我想要的,因为这意味着Apache没有拦截URL。 如果我没有在网站上的Drupal,只是平的HTML,我会得到一个404。(Drupal在这里是不相关的,这只是我自己的情况)。

所以解决scheme可能是删除MultiViews,但我首先必须检查是否有任何需要的情况下。 什么可能有助于使这种调整更具体(因此风险较小将使用RemoveType删除RemoveType文件匹配的URL: http : RemoveType

当使用不存在的URL时,显示类似的外观文件或目录而不是生成404文件未find的错误是非默认行为。

这可能是启用Apache的mod_speling的结果,但更有可能的是,你有一个.htaccess文件重写规则。

默认情况下,Drupal 7部署包含这个.htaccess文件 ,它似乎没有做任何exception的事情,但它确实使用Drupal的index.php作为404错误文档,当Drupal的URL匹配没有.html扩展名的文件名。