2012-01-20 48 views
0

我有一些域都重定向到相同的文件夾(我的public_html)。我想寫一個.htaccess文件,將每個域發送到它自己的文件夾(因此不在導航欄上顯示)。 例如,導航到http://example.com會加載我的服務器的文件夾/public_html/example.com/mod_rewrite重定向主機到另一個文件夾

在另一種情況下,我用這個代碼:

RewriteCond %{HTTP_HOST} example\.com$ [NC,OR] 
RewriteRule ^(.*)$ http://www.anotherdomain.com/$1 [R=301,L] 

但現在我不想重定向到另一個域名;我只是想從另一個文件夾中獲取文件...

它可以實現嗎?提前致謝。

回答

0

更換你有什麼用:

RewriteCond %{REQUEST_URI} !^/%{HTTP_HOST}/ [NC] 
RewriteRule ^(.*)$ /%{HTTP_HOST}/$1 [L] 

對於顯式的主機重定向:

RewriteCond %{HTTP_HOST} example\.com [NC] 
RewriteCond %{REQUEST_URI} !^/example.com/ 
RewriteRule ^(.*)$ /example.com/$1 [L] 

RewriteCond %{HTTP_HOST} otherexample\.com [NC] 
RewriteCond %{REQUEST_URI} !^/abc/otherexample.com/public_html 
RewriteRule ^(.*)$ /abc/otherexample.com/public_html/$1 [L] 
+0

但我明確地說,我希望重定向 「example.com」?假設example.com將從'/ public_html/example.com /'中獲取文件,但是otherexample.com會導致到'/ public_html/abc/otherexample.com/public_html' ... – tyron

+0

是的,您可以製作顯式的host- >目錄映射,請參閱我的編輯 –

+0

表現正是我期待的。謝謝。 – tyron

相關問題