.htaccess将子域重写到目录 [英] .htaccess rewrite subdomain to directory
本文介绍了.htaccess将子域重写到目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以使用.htaccess将子域重写到目录中吗?
Is it possible to use .htaccess to rewrite a sub domain to a directory?
示例:
- http://sub.domain.com/
显示
- http://domain.com/subdomains/sub/
推荐答案
尝试将其放在.htaccess文件中:
Try putting this in your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^(.*)$ http://domain.com/subdomains/sub/$1 [L,NC,QSA]
对于更一般的规则(适用于任何子域,而不仅仅是 sub
)用以下替换最后两行:
For a more general rule (that works with any subdomain, not just sub
) replace the last two lines with this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/subdomains/%1/$1 [L,NC,QSA]
这篇关于.htaccess将子域重写到目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文