的.htaccess指向一个子域到一个目录 [英] .htaccess point a subdomain to a directory
问题描述
我有以下的目录结构:
site.com/
- index.php
- desktop/
-- index.php
- mobile/
-- index.php
site.com的index.php文件重定向到桌面/ index.php文件或移动/ 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
我的应用程序还使用重写,使搜索引擎友好的URL,所以我需要:
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
...
任何建议,.htaccess文件?
Any suggestion to .htaccess file?
先谢谢了。
推荐答案
的RewriteCond%{HTTP_HOST} ^移动
重写规则^ /?(。*)/移动/ $ 1 [PT,L]
RewriteCond %{HTTP_HOST} ^mobile RewriteRule ^/?(.*) /mobile/$1 [PT,L]
的RewriteCond%{HTTP_HOST} ^桌面
重写规则^ /?(。*)/台式机/ $ 1 [PT,L]
RewriteCond %{HTTP_HOST} ^desktop RewriteRule ^/?(.*) /desktop/$1 [PT,L]
在另一方面,如果你想重定向,而不仅仅是直通,即PT改为在每种情况下的R
On the other hand, if you want to redirect, rather than just pass-through, change that PT to an R in each case.
这篇关于的.htaccess指向一个子域到一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!