的.htaccess重写子域目录,并保持子域网址
问题描述:
我需要使用的.htaccess重写一个子域到一个子目录,但保持在子域这样的网址:
I need to rewrite a subdomain to a subdirectory using .htaccess but keep the subdomain in the url like this:
在浏览器中访问网址: sub1.domain.com
Visited url in browser: sub1.domain.com
历任网址: sub.domain.com/sub1 /
我尝试以下
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteRule ^(.*)$ http://subdomain.domain.com/subdomain/$1 [L,NC,QSA]
但是这会导致无限循环。我知道,这将是更容易PHP这样做,但有没有使用的.htaccess这方面的任何解决方案?
but this leads to an endless loop. I know that it would be easier to do this by php but is there any solution for this with using .htaccess?
答
您可以使用文档根目录的规则:
You can use this rule in document root:
RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
RewriteRule ^((?!sub1/).*)$ /sub1/$1 [L,NC]