嵌套子域 URL 重写

发布于 2025-01-05 21:27:14 字数 595 浏览 0 评论 0原文

我看到的格式如下:

nested_subdomain1.nested_subdomain2.domain.com

它可能类似于 test.users.domain.com,我希望能够将此 URL 重写为 test.users .domain2.com

到目前为止,我的运气还不好,我还没有能够从网上找到的示例成功实现可行的解决方案。我尝试过如下一些事情:

RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://domain2.com/$1 [R=301,L]

或者这个......

RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

我不确定我做错了什么,感觉我错过了一些非常明显的东西。

I have a sight that is of the following form:

nested_subdomain1.nested_subdomain2.domain.com

It might be something like test.users.domain.com and I would like to be able to rewrite this URL to something like test.users.domain2.com.

So far, my luck has not proven well and I have not been able to successfully implement a working solution from examples found online. I have tried some things like the following:

RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://domain2.com/$1 [R=301,L]

Or this one...

RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

I am not sure what I am doing wrong and feel like I am missing something really obvious.

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

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

发布评论

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

评论(2

染柒℉ 2025-01-12 21:27:14

试试这个

#match anything1.anything2.domain.com
RewriteCond %{HTTP_HOST} ^([^.]+\.[^.]+)\.domain\.com$ [NC] 
#redirect to anything1.anything2.domain2.com
RewriteRule ^ http://%1.domain2.com%{REQUEST_URI} [R=301,L]

Try this

#match anything1.anything2.domain.com
RewriteCond %{HTTP_HOST} ^([^.]+\.[^.]+)\.domain\.com$ [NC] 
#redirect to anything1.anything2.domain2.com
RewriteRule ^ http://%1.domain2.com%{REQUEST_URI} [R=301,L]
桜花祭 2025-01-12 21:27:14
RewriteCond %{HTTP_HOST} domain\.com$
RewriteRule (*.).mydomain.com mydomain.com/$1

这会将 xx.yy.mydomain.com 转移到 mydomain.com/xx.yy

要替换为斜杠,请尝试

RewriteCond %{HTTP_HOST} domain\.com$
RewriteRule (*.\.).mydomain.com mydomain.com/$1/$2/$3

转移到另一个域,尝试

RewriteCond %{HTTP_HOST} domain\.com$
RewriteRule (*.).mydomain.com $1.mydomain.com [R=301,L]

这会将子域转移到三级。坦率地说,您必须分析 index.php 中的主机以确定调用哪个子域,因此不妨使用第一个

RewriteCond %{HTTP_HOST} domain\.com$
RewriteRule (*.).mydomain.com mydomain.com/$1

This will trasnfer xx.yy.mydomain.com to mydomain.com/xx.yy

To replace with slashes, try

RewriteCond %{HTTP_HOST} domain\.com$
RewriteRule (*.\.).mydomain.com mydomain.com/$1/$2/$3

To transfer to another domain ,try

RewriteCond %{HTTP_HOST} domain\.com$
RewriteRule (*.).mydomain.com $1.mydomain.com [R=301,L]

This will transfer the subdomains upto a level of three. Frankly, you will have to analyze the host in your index.php to determine which subdomain is caled, so might as well use the first one

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