Apache 2.2 <Location>错误:试图服务目录,不重写

安装程序:Apache 2.2(Windows,win32)。

httpd.conf片段:

Alias /custom /var/www/custom DirectoryIndex index.html <Location /custom> SetHandler custom_handler DirectoryIndex index.html </Location> <Directory /var/www> Allow From all Options +Indexes AllowOverride all DirectoryIndex index.html </Directory> 

也:

  • mod_dir,mod_rewrite已激活
  • index.html存在于/ var / www / custom中
  • 服务器进程UID可以读取/ var / www中的所有文件/目录
  • Apache服务在所有接口上侦听
  • 自定义处理程序处理位置path中的某些URL,其他从文件系统处理; 如同没有处理程序一样处理index.html

问题:

  • 以位置path开始重写URL不起作用(没有错误报告)
  • 当试图服务http://服务器/自定义 (没有closures斜线)时,会发生以下情况:
    • Apacheredirect到http:// ServerName / custom / (到ServerName指令值)
    • “尝试服务目录”被写入错误日志为/ var / www / custom /
    • 404错误返回

以上是如何处理的? 以下是要求:

  • 服务/var/www/custom/index.html当http://服务器/自定义input,或
  • 重写某些url,例如

    RewriteRule ^ custom / $ / custom / index.html [L,R]

上面的重写规则不pipe用,放在哪里(位于内部或外部)

您正在混合将URI映射到文件系统的一部分的几种不同的方式,而且它们并不一起工作。

首先,如果你的DocumentRoot/var/www ,那么AliasMap是完全不必要的。 虽然这不是你的代码片段。

其次,由于/var/www/custom是一个目录,因此在引用它时应该使用Directory伪指令。 Location被用于不是目录的东西,但是你想要像以前一样行事。

要清除这些点,请尝试更改您的configuration,如下所示:

 Alias /custom /var/www/custom # ONLY if you don't have /var/www as DocumentRoot! DirectoryIndex index.html <Directory /var/www> Allow From all Options +Indexes AllowOverride all </Directory> <Directory /var/www/custom> SetHandler custom_handler </Directory>