开发者

Apache subdomain and domain redirections

I have the following situation to tackle, i have a domain and a subdomain pointing to the same resource.

www.mydomain.com and sub1.mydomain.com

What i'm trying to achieve is the following:

i would like the subdomain to

  1. redirect its root to a sub-folder of the system. So sub1.mydomain.com --> sub1.mydomain.com/subdomainsrootfolder/sub1/

  2. redirect back to the main domain when a uri not below the "/subdomainsrootfolder/sub1/" structure is requested. i.e. sub1.mydomain.com/subsrootfolder/sub1/(开发者_如何学C) to be served normally but if sub1.mydomain.com/() is requested to redirect to www.mydomain.com/(*)

thanks a lot for any insights!

ex.

case 1. sub1.domain.com --> sub1.domain.com/subrootfolder/sub1/

case 2. sub1.domain.com/subrootfolder/sub1/* --> as is

case 3. sub1.domain.com/anyotherfolder/ --> www.domain.com/anyotherfolder/

case 4. www.domain.com/subrootfolder/sub1/* --> sub1.domain.com/subrootfolder/sub1/*

maybe these examples are more explanatory than the text above... :)


RewriteCond %{HTTP_HOST} www\.mydomain\.com
RewriteRule ^/subrootfolder/sub1/(.*) sub1.domain.com/subrootfolder/sub1/$1 [redirect,last]

RewriteCond %{HTTP_HOST} www\.mydomain\.com
RewriteRule / - [last]

RewriteRule ^/$ sub1.mydomain.com/subdomainsrootfolder/sub1/ [redirect,last]
RewriteRule ^/subdomainsrootfolder/sub1/ - [last]
RewriteRule ^/(.*) www.mydomain.com/$1 [redirect,last]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜