使用 Apache 将空白子域重定向到另一个子域的最佳方法是什么?
我希望将任何对 http://example.com/* 的请求重定向到 http://www.example.com/*。
其中 * 是任意路径。
I want any request to http://example.com/* to be redirected to http://www.example.com/*.
Where * is any arbitrary path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Apache 的 mod_alias 模块执行永久重定向,例如:
放置重定向在空白子域的虚拟主机块或根级
.htaccess
文件内。“http://www.example.com/”上的尾随 / 至关重要。
Use Apache's mod_alias module to do a permanent redirect like:
Place the redirect inside the blank subdomain's virtualhost block or root level
.htaccess
file.The trailing / on "http://www.example.com/" is crucial.
我将在此处添加另一个选项,我也用它来允许其他特定主机。 例如,如果除了 www.example.com 网站之外,您还想要 dev.example.com 和 blog.example.com 网站,请将其放入根级别 .htaccess 文件中:
I'll add another option here that I've used to allow for other specific hosts as well. For example if you wanted a dev.example.com and a blog.example.com site in addition to your www.example.com site, put this in your root level .htaccess file: