开发者

.htaccess point a subdomain to a directory

开发者 https://www.devze.com 2023-02-26 03:53 出处:网络
I have the following directory structure: site开发者_开发知识库.com/ - index.php - desktop/ -- index.php

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

精彩评论

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