通配符子域的透明重写/传递

发布于 2024-10-16 06:14:41 字数 884 浏览 1 评论 0原文

我即将实现我的目标,但我无法想出正确的解决方案来解决我的问题。

我为我的通配符子域编写了以下规则:

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

#rewrite subdomains to /club/<clubname as defined by subdomain>/<whatever was here before>
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/club/%1/$0 [NC,L]

这非常接近我的要求,即如果我转到 http://alpha.domain.com/some/string/here URL 被重写为 http://domain.com/club/alpha/some/string/here

但是

我希望浏览器中的网址仍然看起来像原始网址

提前非常感谢

编辑< /strong>:我尝试将 PT 添加到最终规则中,但这不起作用,我收到 400 错误

EDIT2:对于任何感兴趣的人,我放弃了这一行查询,而是使用 php 来读取子域中的文本。

I am close to achieving my goal but I cannot come up with the correct solution to my problem.

I have written the following rules for my wildcard subdomains:

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

#rewrite subdomains to /club/<clubname as defined by subdomain>/<whatever was here before>
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/club/%1/$0 [NC,L]

This is desperately close to what I require, ie if I go to http://alpha.domain.com/some/string/here the URL is rewritten to http://domain.com/club/alpha/some/string/here

however

I would like the url in browser to still look like the original url

Many thanks in advance

EDIT: I have tried just adding PT to the final rule but that doesn't work, I get a 400 error

EDIT2: For anyone interested, I abandoned this line of enquiry and instead used php to read the text in the subdomain.

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

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

发布评论

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

评论(1

奢望 2024-10-23 06:14:41

如果 www.example.com 子域与 example.com 域使用相同的虚拟主机,您可以使用相对路径进行内部重写:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteCond $0 !^club/
RewriteRule ^(.*)$ club/%1/$0 [NC,L]

否则您将需要代理:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/club/%1/$0 [NC,L,P]

If the www.example.com subdomain uses the same virtual host as the example.com domain, you can just use an internal rewrite by using a relative path:

RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteCond $0 !^club/
RewriteRule ^(.*)$ club/%1/$0 [NC,L]

Otherwise you will need a proxy:

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