繁体   English   中英

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

[英]How to redirect non-www to www url in 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]

您可能最有Windows共享主机。 我看到许多Windows共享托管服务都无法让您访问Mod_Rewrite函数。 如果是这样,请让您的托管服务提供商在此方面为您提供帮助。 一旦完成这些操作,然后取消注释代码。

你做这样的事情,

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

您可以尝试使用“ 域默认重定向”或其他一些类似的模块。 它将所有子域重定向到指定的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

尝试这个,

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

确保您的.htaccess文件路径在根目录中。

希望它的作品..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM