mod_rewrite 条目的正确位置在哪里?
看在上帝的份上,我似乎无法让这个 mod_rewrite 正常工作。让我在这里问,而不是进行蛮力试错。
- 我希望 mod_rewrite 规则适用于所有域。
- 我想要 httpd.conf 中的 mod_rewrite 条目
我想要摆脱这个 WWW 病毒(出于 SEO 目的):
我想摆脱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.
- I want mod_rewrite rules to apply to ALL domains.
- I want mod_rewrite entries in httpd.conf
I want to get rid of this WWW virus (for SEO purposes):
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这为我解决了。正如我怀疑的那样,应用重写规则的地方存在很大的差异。包括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.