开发者

.htaccess point a subdomain to a directory

I have the following directory structure:

site开发者_开发知识库.com/
- index.php
- desktop/
-- index.php
- mobile/
-- index.php

The index.php of site.com redirects to desktop/index.php or mobile/index.php, depending of user platform.

The problem is that I need different subdomains to point to respective directories:

mobile.site.com -> site.com/mobile
desktop.site.com -> site.com/desktop

My application also uses rewrite to make SEO friendly URL's, so I need:

mobile.site.com/login -> site.com/mobile/login
mobile.site.com/user/1 -> site.com/mobile/user/1
...

Any suggestion to .htaccess file?

Thanks in advance.


RewriteCond %{HTTP_HOST} ^mobile RewriteRule ^/?(.*) /mobile/$1 [PT,L]

RewriteCond %{HTTP_HOST} ^desktop RewriteRule ^/?(.*) /desktop/$1 [PT,L]

On the other hand, if you want to redirect, rather than just pass-through, change that PT to an R in each case.


Try this

RewriteCond %{HTTP_HOST} ^(.*).site.com$

RewriteRule (.*) %1/$1 [L]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜