.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]