【问题标题】:RewriteBase needed when using mod_alias使用 mod_alias 时需要 RewriteBase
【发布时间】:2015-02-05 09:56:44
【问题描述】:

在我的 apache 配置中,我创建了一个别名:

<IfModule alias_module>
    Alias /projecten "C:/Users/Youri/SkyDrive/Projecten"
</IfModule>

<Directory "C:/Users/Youri/SkyDrive/Projecten">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride FileInfo Options

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

在“projecten/mvc”文件夹中,我有一个 .htacces 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(.*) public/$1 [L]
</IfModule>

当我转到浏览器 http://localhost/projecten/mvc/ 时,我收到一条错误消息:

在此服务器上找不到请求的 URL /Users/Youri/SkyDrive/Projecten/mvc/public/。

当我将文件夹 (mvc) 复制到我的文档根目录并导航到 http://localhost/mvc/ 时,重写工作..

当我添加到项目文件夹中的 htaccess 文件时:

RewriteBase /projecten/mvc

它可以工作,但我不想添加 RewriteBase,因为当我将它放在文档根目录中时我不需要它...

谁能告诉我怎么回事?

Apache/2.4.10 (Win64) OpenSSL/1.0.1j PHP/5.6.4 已配置

【问题讨论】:

  • 一切正常;您需要指定一个 RewriteBase 只是因为它是在您使用的设置下正常工作所必需的。
  • httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritebase: “当您在每个目录 (htaccess) 上下文中使用相对路径进行替换时,此指令是必需的,除非满足以下任一条件为真:原始请求和替换位于 DocumentRoot 下(与通过其他方式(例如别名)可访问相反)。 [或] 包含 RewriteRule 的目录的文件系统路径,以相对替换为后缀,作为服务器上的 URL 路径也是有效的(这种情况很少见)。”
  • “(而不是通过其他方式可访问,例如 Alias)” 正是您在这里所拥有的,因此您需要指定 RewriteBase ,因为您也在使用替换中的相对路径……完全按照文档说明工作。
  • 好的,谢谢你的解释!

标签: apache .htaccess mod-rewrite mod-alias


【解决方案1】:

这里没有“出错”的地方。您需要指定 RewriteBase 只是因为它是在您使用的设置下正常工作所必需的。

http://httpd.apache.org/docs/2.2/en/mod/mod_rewrite.html#rewritebase:

当您在每个目录 (htaccess) 上下文中使用相对路径进行替换时,此指令是必需的,除非满足以下任一条件:
- 原始请求和替换位于 DocumentRoot 下(而不是通过其他方式(例如别名)可访问)。
- 包含 RewriteRule 的目录的文件系统路径,以相对替换为后缀,作为服务器上的 URL 路径也是有效的(这种情况很少见)。”

“(而不是通过其他方式可访问,例如别名)” 正是您在此处所拥有的,因此您需要指定 RewriteBase,因为您也在您的替换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-09
    • 2011-06-13
    • 1970-01-01
    • 2011-06-18
    • 2010-10-22
    相关资源
    最近更新 更多