AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 660548
Accepted
Konstantin Boyandin
Konstantin Boyandin
Asked: 2015-01-19 22:44:04 +0800 CST2015-01-19 22:44:04 +0800 CST 2015-01-19 22:44:04 +0800 CST

Apache 2.2 <Location> 错误:尝试提供目录,没有重写

  • 772

设置: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 激活
  • /var/www/custom 中的 index.html
  • 服务器进程 UID 可以读取 /var/www 中的所有文件/目录
  • Apache 服务监听所有接口
  • 自定义处理程序处理位置路径中的某些 URL,其他从文件系统提供;index.html 被处理为好像没有处理程序存在

问题:

  • 重写以位置路径开头的 URL 不起作用(未报告错误)
  • 当尝试服务http://server/custom(不关闭斜杠)时,会发生以下情况:
    • Apache 重定向到http://ServerName/custom/(到 ServerName 指令值)
    • “尝试服务目录”被写入 /var/www/custom/ 的错误日志
    • 返回 404 错误

上述情况如何处理?以下是必需的:

  • 输入http://server/custom时提供 /var/www/custom/index.html ,或
  • 重写某些 URL,例如

    重写规则 ^custom/$ /custom/index.html [L,R]

上面的重写规则不起作用,无论它放在哪里(在位置内或位置外)

apache-2.2
  • 1 1 个回答
  • 4548 Views

1 个回答

  • Voted
  1. Best Answer
    Jenny D
    2015-01-20T00:02:04+08:002015-01-20T00:02:04+08:00

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

    首先,如果你的DocumentRootis /var/www,那么 AliasMap 是完全没有必要的。不过,这从您的代码段中并不清楚。

    其次,由于是一个目录,所以在引用它时/var/www/custom应该使用该指令。用于不是目录但您想表现得好像它们是目录的东西。DirectoryLocation

    要清除这些要点,请尝试像这样更改您的配置:

    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>
    
    • 2

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve