如何 302 重定向请求,除非它针对特定的子域/文件夹?

发布于 2024-12-27 02:34:42 字数 1549 浏览 5 评论 0 原文

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

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

发布评论

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

评论(2

闻呓 2025-01-03 02:34:42
RewriteEngine on
RewriteBase /
#redirect to domain2 if on domain1.com and path doesn't start with /blog
RewriteCond %{HTTP_HOST} !=domain1.com
RewriteCond $0 !^blog
RewriteRule .* http://domain2.com/$0
RewriteEngine on
RewriteBase /
#redirect to domain2 if on domain1.com and path doesn't start with /blog
RewriteCond %{HTTP_HOST} !=domain1.com
RewriteCond $0 !^blog
RewriteRule .* http://domain2.com/$0
澉约 2025-01-03 02:34:42

RewriteCond >HTTP_HOST 位于执行重定向的 RewriteRule 之上。您甚至可以为您不想重定向的人编写它,然后否定它。

例如:

RewriteCond %{HTTP_HOST} !=Domain1.com

请注意,您可以有多个 RewriteCond,但每个分组(一个或多个)仅适用于下一个 RewriteRule*。

Add a RewriteCond around HTTP_HOST above your RewriteRule doing the redirect. You can even write it for the one you don't want to redirect for, and negate it.

For example:

RewriteCond %{HTTP_HOST} !=Domain1.com

Note that you can have multiple RewriteConds, but each grouping (one or more) will only apply to the very next RewriteRule*.

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