文件夹重定向到子域 [英] Redirect folder to subdomain
问题描述
我想有2的Ruby on在域Rails应用程序。
I want to have 2 Ruby on Rails applications on a domain.
第一个是在 example.com
运行;我这样做,是用的.htaccess(与重写规则,以 example.com:12001
)
The first one is running at example.com
; I have done that with .htaccess (with RewriteRule to example.com:12001
)
我想另一个是在一个子域名,如 blog.example.com
。所以,我创建了一个子域,并在该文件的.htaccess我重定向到 example.com:12002
。
I want the other one to be in a subdomain, like blog.example.com
. So I created a subdomain, and in the file .htaccess I redirect to example.com:12002
.
一切工作正常,但如果我去解决 example.com/blog
,我不是重定向,我在浏览器中看到博客的文件夹中的public_html的内容
Everything is working fine, but if I go to address example.com/blog
, I am not redirected, and I see in browser the contents of blog folder in public_html:
Index of /blog
Parent Directory
我想转到第二个应用程序(blog.example.com <$ C C $>)当网址 example.com/blog
。我怎么能这样做呢?
I would like to go to the second application(blog.example.com
) when the url is example.com/blog
. How could I do that?
推荐答案
解决方案取决于您的托管服务提供商实现多子域映射。有些提供的控制面板,让您可以注册子域,每个指向您的文件空间中的单独的子目录。有的将映射 *。yourdomain.zzz
文档根目录的 yourdomain.zzz
,并从你的描述,这种是正在发生的事情给你。在这种情况下,你需要去code在 HTTP_HOST 变量和路径上。但是你也需要停止你的重写规则的循环,使 sub1.yourdomain.zzz
不被映射到yourDocRoot / SUB1 / SUB1 / SUB1 ...`
the solution depends on how your hosting provider implements multi-subdomain mapping. Some offer a control panel so that you can register your subdomains and point each to a separate subdirectory in your file space. Some will just map *.yourdomain.zzz
to the document root for yourdomain.zzz
, and from your description, this is what is happening for you. In this case you need to decode the HTTP_HOST variable and route on that. But you also need to stop your rewrite rule looping so that sub1.yourdomain.zzz
doesn't get mapped to yourDocRoot/sub1/sub1/sub1...`
如果你想处理的 SUB1 和 SUB2 的子域,那么你可以这样做,在你的规则顶层是这样的:
If you wanted to process sub1 and sub2 subdomains, then you would do this with a rule in you top level like this:
RewriteBase /
RewriteCond %{ENV:REDIRECT_INSUB} !=1
RewriteCond %{HTTP_HOST} (sub1|sub2)\.yourdomain\.zzz
ReweriteRule ^(.*) %1/$1 [L,E=INSUB:1]
搜索 [的.htaccess] HTTP_HOST 即可看到大量的这种变体。
Search for [.htaccess] HTTP_HOST to see lots of variants of this.
这篇关于文件夹重定向到子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!