htaccess redirect url from non www to www

Redirecting all links for domain.com to www.domain.com

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

Redirecting all links for www.domain.com to domain.com

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^/?$ “http\:\/\/domain\.com\/” [R=301,L]

Leave a Reply

Your email address will not be published. Required fields are marked *