如何将某些请求重定向到另一个域?

发布于 2024-12-23 11:55:17 字数 428 浏览 0 评论 0原文

我建立了一个网站并更改了旧网站的名称。因此暂时有 2 个站点正在运行。

  • www.mydomain.com(新站点)
  • legacy.mydomain.com(旧站点)

问题是仍然有一些流量错误地到达新站点,我不希望我的 Rails 应用程序处理这个问题(rails 有点慢并且需要大量资源)。 相反,我希望 apache 在到达 Rails 应用程序之前将其重定向到旧的。

错误的流量网址总是类似于“www.mydomain.com/bbs/...”。所以我想过滤掉带有'/bbs/'的请求并将其重定向到“legacy.mydomain.com/bbs/...”。我想我可以在我的 .htaccess 文件上做到这一点。但我不知道如何写规则。 mod_rewrite 安装在我的服务器上。

你能帮忙吗? 谢谢。

山姆

I set up a site and changed the old site's name. So temporarily 2 sites are running.

  • www.mydomain.com (new site)
  • legacy.mydomain.com (old site)

The problem is that still some traffic comes to the new site mistakenly and I don't want my rails application to handle that (rails is kinda slow and takes lotta resources).
Instead, I want apache to redirect it to the old one before it reaches to the rails app.

The wrong traffic url is always like "www.mydomain.com/bbs/...". So I want to filter out requests with '/bbs/' and redirect it to "legacy.mydomain.com/bbs/...". I think I can do that on my .htaccess file. But I don't know how to write the rule. mod_rewrite is installed on my server.

Can you help?
Thanks.

Sam

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

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

发布评论

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

评论(1

自由如风 2024-12-30 11:55:17

尝试:

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$   [NC]
RewriteRule ^bbs/ http://legacy.mydomain.com%{REQUEST_URI}  [R=301,L]

Try:

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