mod_rewrite 条目的正确位置在哪里?

发布于 2024-09-28 04:46:54 字数 1117 浏览 0 评论 0原文

看在上帝的份上,我似乎无法让这个 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

非常感谢。这一切很快就变得如此混乱。

玛丽亚

For the love of God, I can't seem to get this mod_rewrite working properly. Instead of doing brute force trial-and-error, let me ask here.

  1. I want mod_rewrite rules to apply to ALL domains.
  2. I want mod_rewrite entries in httpd.conf
  3. I want to get rid of this WWW virus (for SEO purposes):

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

  4. I want to get rid of index.html (for SEO, google indexes it instead of just domain):

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

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

Domains are inside <virtualhost> entries. I couldnt figure out where to put what or which one should take priority. As i mentioned, I would like to apply these 2 rules to ALL DOMAINS in the server.

The situation is exacerbated by ssl.conf. Will all these need to be entered into ssl.conf too? What will happen when there are 2 redirects like:

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

Thank you so much. This has quickly become all so confusing.

Maria

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘴硬脾气大 2024-10-05 04:46:54

这为我解决了。正如我怀疑的那样,应用重写规则的地方存在很大的差异。包括mean在内的许多人似乎都没有意识到这一点。

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

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

This solves it for me. As I suspected, there is a whole lotta difference where rewriterule is applied. Many people including mean seems to be unaware of this.

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

The Apache HTTPD Server deals with requests in discrete phases. While this is usually transparent to the user and administrator it does have an effect on the behaviour of mod_rewrite when rulesets are placed in different contexts. To oversimplify a little, when rules are placed in VirtualHost blocks (or in the main server context) they get evaluated before the server has yet mapped the requested URI to a filesystem path. Conversely, when rules are placed in .htaccess files, or in Directory blocks in the main server config, they are evaluated after this phase has occured.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文