.htaccess point a subdomain to a directory

时间秒杀一切 提交于 2020-03-21 06:59:04

问题


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.


回答1:


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.




回答2:


Try this

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

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



来源:https://stackoverflow.com/questions/5664459/htaccess-point-a-subdomain-to-a-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!