2011-11-22 13 views
1

我有一個網站:www.asdf.com和www.fdsa.com我如何重定向到不同的頁面因與重寫條件/規則的HOSTNAME .htacces

別名我如何檢查.htaccess中的HOSTNAME並將它們重定向到不同的頁面?

我知道它是沿此線的東西:

RewriteRule (%{HTTP_HOST})^(.*)$ http://www.gunslot.com/$2 [L,R=301] 

基本上我怎麼做的這一個相當於在.htaccess(僞代碼)

if(hostname == "asdf") redirect to asdf.com/hello.html 
if(hostname == "fdsa") redirect to asdf.com/goodbye.html 

回答

1

不是100%清楚什麼你試圖達到,但這個答案就是你所問的。

的.htaccess

RewriteCond %{HTTP_HOST} ^asdf\.com 
RewriteRule ^(.*)$ http://asdf.com/hello.html [NC,L] 

RewriteCond %{HTTP_HOST} ^fdsa\.com 
RewriteRule ^(.*)$ http://asdf.com/goodbye.htm [NC,L] 
0

如果你想重定向到任何要求航空自衛隊航空自衛隊上域hello.html的,並FDSA任何請求goodbye.html添加以下到您的域的根目錄中的.htaccess文件。

RewriteEngine On 
RewriteBase/
#Redirect any asdf domain or subdomain 
RewriteCond %{HTTP_HOST} ^(.+\.)?asdf\.com$ [NC] 
RewriteCond %{REQUEST_URI} !^/(hello|goodbye)\.html$ [NC] 
RewriteRule . http://asdf.com/hello.html [L,R] 

#Redirect any fdsa domain or subdomain 
RewriteCond %{HTTP_HOST} ^(.+\.)?fdsa\.com$ [NC] 
RewriteRule . http://asdf.com/goodbye.htm [L,R] 
+0

爲什麼:'RewriteCond%{HTTP_HOST} ^(。+ \。)?asdf \ .com $ [NC]'??它不應該是'*'而不是'?'=> **'RewriteCond%{HTTP_HOST} ^(。+ \。)* asdf \ .com $ [NC]'**? –

+0

'?'和'*'都可以使子域成爲可選項,但'*'可以允許**任意數量的子域發生,例如, 'www.ww1.ww2.www3.asdf.com',而'?'只允許** 1 **。 –