How to Redirect Non www to www in .htaccess?

Learn how to redirect non www to www domain in .htaccess?

Redirecting non www to www

If you would like to access your website as both yourdomain.com and www.yourdomain.com, then this can be done through redirection. This tutorial will help you to learn how to redirect non www to www domains in .htaccess file. Redirecting non www to www domain will allow you to access your website both with www and without www.

You should add the mod_rewrite rule code in the beginning of .htaccess file.

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


Related Topics