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

Hi I faced a problem in Drupal CMS. I browse online but i not found any result about this. In different places we read that open .htaccess file and uncomment the following lines by removine hash tag from start but this is not working please help me out.

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

You may have Windows shared hosting most probably. I saw many Windows shared hosting services don't give you access to the Mod_Rewrite functions. If this is true so please ask your hosting provider to help you out in this. Once they done with that then uncomment the code.

try this,

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

make sure your .htaccess file path is in root.

Hope its works..

You do something like this.,

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

You may try to use Domain Default Redirection or some other similar modules. It redirecting all subdomains to the specified URL while still serving Drupal content to the subdomains set in Domain Access.

Or if you still want to use rewrite rules, try the following rule (non-www to 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]

or in the other direction (www to non-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]

See: https://www.drupal.org/node/499104