【问题标题】:Why does fatfree need a RewriteBase on Mac but not Ubuntu?为什么 fatfree 在 Mac 上需要 RewriteBase 而不是 Ubuntu?
【发布时间】:2013-07-13 12:10:19
【问题描述】:

我最近在 Ubuntu 上使用了很多 FatFree,并且将它放入子目录没有问题。但是,我最近尝试在 Mac (10.6.8) 上的用户网站上执行此操作,结果遇到了problem of needing a RewriteBase for the routing to work

我想知道是否有人知道为什么 Ubuntu 上的默认 Apache 设置似乎允许路由在 .htaccess 中没有 RewriteBase 的情况下工作,但 Mac 上的设置使它成为必要。

Ubuntu 设置使用一堆虚拟主机,而 Mac 配置只有一个服务器配置,启用了 mod_userdir 和一个针对每个用户的站点目录的指令。

【问题讨论】:

    标签: macos ubuntu apache2 fat-free-framework


    【解决方案1】:

    mod_rewrite documentation 表示需要 RewriteBase 指令,除非满足以下任一条件:

    • 原始请求和替换位于 DocumentRoot 下(而不是可通过其他方式访问,例如 Alias)。
    • 包含 RewriteRule 的目录的文件系统路径(以相对替换为后缀)作为服务器上的 URL 路径也是有效的(这种情况很少见)。

    您的 Ubuntu 设置可能满足第一个条件,但您的 Mac 设置不满足,因为您使用的是 mod_userdir。如果您将文件从 ~/Sites 移动到 DocumentRoot(Mac 上的默认值为 /Library/Webserver/Documents),您可能不再需要 RewriteBase。

    【讨论】:

    • 是的,你是对的。在 /Library/Webserver/Documents/fatfree-master 中,没有 RewriteBase 也能正常工作!谢谢!
    【解决方案2】:

    我不确定,但我可以告诉你,大多数 apache 设置都将 RewriteBase / 作为默认值,如果你的 F3 位于 webroot 上,那么再次将其写入 .htaccess 文件是多余的。 mac 上的 MAMP 设置中可能缺少这部分。

    在虚拟主机或 webroot 的子目录中运行 F3 通常总是需要有效的 RewriteBase 定义。

    可以在此处找到有关此的其他信息:

    https://github.com/bcosca/fatfree/wiki/FAQ#can-i-run-f3-in-a-sub-directory

    【讨论】:

      【解决方案3】:

      让我解释一下您应该如何分析 Mac 和 Ubuntu 配置之间的差异,以便您了解为什么其中一个需要 RewriteBase 而另一个不需要。将此添加到您的 Apache 配置中:

      RewriteLog /var/log/apache2/error.log
      RewriteLogLevel 9
      

      【讨论】:

      • 谢谢!您是否有任何指向日志格式含义的链接?关于每个请求,我有几十行,其中没有提到 RewriteBase,或者似乎表明 RewriteBase 有任何影响。
      猜你喜欢
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 2018-03-18
      • 2019-04-02
      • 2012-02-10
      • 2018-07-30
      • 2011-06-18
      • 2021-04-13
      相关资源
      最近更新 更多