【问题标题】:Where is the proper place for mod_rewrite entries?mod_rewrite 条目的正确位置在哪里?
【发布时间】:2011-04-26 15:27:34
【问题描述】:

看在上帝的份上,我似乎无法让这个 mod_rewrite 正常工作。让我在这里问,而不是进行蛮力试错。

  1. 我希望 mod_rewrite 规则适用于所有域。
  2. 我想要 httpd.conf 中的 mod_rewrite 条目
  3. 我想摆脱这个 WWW 病毒(出于 SEO 目的):

    http://www.example.com > http://example.com

  4. 我想摆脱 index.html(对于 SEO,谷歌索引它而不仅仅是域):

    http://www.example.com/index.html > http://example.com

    http://www.example.com/some/index.html > http://example.com/some/index.html

域位于<virtualhost> 条目中。我不知道在哪里放置什么或哪个应该优先。正如我所提到的,我想将这两条规则应用于服务器中的所有域。

ssl.conf 加剧了这种情况。所有这些都需要输入 ssl.conf 吗?当有 2 个重定向时会发生什么,例如:

http://www.example.com/index.html > http://example.com/index.html > http://example.com

非常感谢。这很快就变得如此令人困惑。

玛丽亚

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    这为我解决了这个问题。正如我所怀疑的那样,应用重写的地方有很大的不同。包括mean在内的许多人似乎都没有意识到这一点。

    http://wiki.apache.org/httpd/RewriteContext

    Apache HTTPD 服务器处理离散阶段的请求。虽然这通常对用户和管理员是透明的,但当规则集放置在不同的上下文中时,它确实会对 mod_rewrite 的行为产生影响。为了简化一点,当规则被放置在 VirtualHost 块中(或在主服务器上下文中)时,它们在服务器尚未将请求的 URI 映射到文件系统路径之前被评估。相反,当规则放置在 .htaccess 文件或主服务器配置中的目录块中时,它们会在此阶段发生后进行评估。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多