如何在drupal中将非www重定向到www url

时间:2013-11-28 08:23:02

标签: php .htaccess drupal

您好我在Drupal CMS中遇到了问题。我在网上浏览但没有找到任何关于此的结果。在不同的地方,我们读取打开的.htaccess文件,并通过从开始删除哈希标记取消注释以下行,但这不起作用请帮助我。

# 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]

4 个答案:

答案 0 :(得分:3)

您最有可能拥有Windows共享托管。我看到许多Windows共享托管服务不允许您访问Mod_Rewrite功能。如果这是真的,请让您的托管服务提供商帮助您解决此问题。完成后,取消注释代码。

答案 1 :(得分:2)

你做这样的事情。

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

答案 2 :(得分:2)

您可以尝试使用Domain Default Redirection或其他类似的模块。它将所有子域重定向到指定的URL,同时仍将Drupal内容提供给域Access中设置的子域。

或者,如果您仍想使用重写规则,请尝试以下规则(非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

答案 3 :(得分:1)

试试这个,

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

确保您的 .htaccess 文件路径位于root。

希望它的作品......