2016-11-21 51 views
0

我想解決一個簡單的問題,我試圖將我的www.example.co.za域重定向到我的www.example.com域。.htaccess重定向到example.com而不是www.example.com

.co.za域我已經寫了.htaccess文件具有以下內容:

Redirect 301/http://www.example.com/ 

腳本似乎運行,但不幸的是我沒有得到期望的結果。

在導航到.co.za域時,頁面被重定向到example.com,這不是我的預期結果,我想要www.example.com

關於如何解決這個問題的任何想法?

關於.com我寫了相同的.htaccess代碼,但仍然沒有任何成功。任何幫助深表感謝!

回答

1

您應該使用mod_rewrite的是,這裏是重定向不是example.com(包括www.example.co.za)任何域爲例來example.com:

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

還要檢查在您的VirtualHost聲明中,www.example.com,www.example.co.za或任何其他需要的域都被正確配置爲ServerNameServerAlias

如果DNS條目指向不同的服務器上,你唯一的解決辦法是使用一個簡單的HTTP重定向元(www.example.co服務器上)來創建一個客戶端重定向:

<html> 
    <head> 
     <meta http-equiv="refresh" content="durée;URL=http://www.example.co.za"> 
    </head> 
    <body> 
     Redirecting to <a href="http://www.example.co.za">www.example.co.za</a>... 
    </body> 
<html> 
+0

'的RewriteCond%{HTTP_HOST} !^ http:// www \ .example \ .com $ RewriteRule(。*)http://www.example.com/$1 [R = 301,L]' 這會爲我的工作做好一切'www .example.com「呢? –

+0

是的,它會!請接受並點贊。 :-) –

+0

尚未開始工作...... –

相關問題