2013-11-28 39 views
1

您好,我在Drupal CMS中遇到了一個問題。我在網上瀏覽,但我沒有發現任何結果。在不同的地方,我們讀取打開的.htaccess文件,並從開始取消註釋以下行的刪除哈希標記,但這是行不通的,請幫助我。如何在drupal中將非www重定向到www url

# To redirect all users to access the site WITH the 'www.' prefix, 
# (http://example.com/... will be redirected to http://www.example.com/...) 
# uncomment the following: 
# RewriteCond %{HTTP_HOST} . 
# RewriteCond %{HTTP_HOST} !^www\. [NC] 
# RewriteRule^http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+0

取消註釋該代碼的最後3行。如果它不起作用,你沒有安裝/啓用mod_rewrite。 – Clive

回答

3

您可能有Windows共享主機最有可能。我看到許多Windows共享託管服務不允許您訪問Mod_Rewrite功能。如果這是真的,那麼請讓您的託管服務提供商在此幫助您。一旦他們完成了,然後取消註釋代碼。

1

試試這個,

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www.yourdomain.com$ [NC] 
RewriteRule .? http://www.yourdomain.com%{REQUEST_URI} [R=301,L] 

確保您的.htaccess文件路徑是根。

希望其作品..

2

你做這樣的事情,

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^yourdomain.com.*$ [NC] 
RewriteRule ^(.*)$ http://www.yourdomain.com%{REQUEST_URI} [L,R=301] 
2

您可以嘗試使用Domain Default Redirection或其他類似的模塊。它將所有子域重定向到指定的URL,同時仍然將Drupal內容提供給在域訪問中設置的子域。

或者,如果你仍然想使用重寫規則,請嘗試以下規則(非www到www):

# Redirect all users to access the site WITH the 'www.' prefix 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteCond %{HTTP_HOST} !\.([a-z-]+\.[a-z]{2,6})$ [NC] 
    RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

或在其他方向(WWW到非www):

# Redirect all users to access the site WITHOUT the 'www.' prefix 
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
    RewriteCond %{HTTP_HOST} !\.([a-z-]+\.[a-z]{2,6})$ [NC] 
    RewriteRule^http://%1%{REQUEST_URI} [L,R=301] 

參見:https://www.drupal.org/node/499104