Drupal 8 redirect to www or non-www

Edward Ziadeh • 28 February 2019
0 comments
0 likes

To redirect all the users from www to non-www go to .htaccess file and uncomment or add the following

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

and for non-ww redirect use

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]