使用 Apache 将空白子域重定向到另一个子域的最佳方法是什么?

发布于 2024-07-13 23:28:38 字数 216 浏览 4 评论 0原文

我希望将任何对 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 技术交流群。

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

发布评论

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

评论(2

苍白女子 2024-07-20 23:28:38

使用 Apache 的 mod_alias 模块执行永久重定向,例如:

RedirectPermanent / "http://www.example.com/"

放置重定向在空白子域的虚拟主机块或根级 .htaccess 文件内。

http://www.example.com/”上的尾随 / 至关重要。

Use Apache's mod_alias module to do a permanent redirect like:

RedirectPermanent / "http://www.example.com/"

Place the redirect inside the blank subdomain's virtualhost block or root level .htaccess file.

The trailing / on "http://www.example.com/" is crucial.

桃扇骨 2024-07-20 23:28:38

我将在此处添加另一个选项,我也用它来允许其他特定主机。 例如,如果除了 www.example.com 网站之外,您还想要 dev.example.com 和 blog.example.com 网站,请将其放入根级别 .htaccess 文件中:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^dev\.example\.com
RewriteCond %{HTTP_HOST} !^blog\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L,QSA]

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:

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} !^dev\.example\.com
RewriteCond %{HTTP_HOST} !^blog\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L,QSA]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文