Redirect non-www to www in Linux (Apache)

Create a file .htaccess in the document root of your site with the following code.  If this file already exists, prepend the following code to it:

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)