Enforcing WWW URLs with 301 Redirect using .htaccess file

Friday, 16. September 2011

If you want to enforce www to your URLs or simply redirect everything to a new URL with .htaccess file, this may help you.

1) Open your .htaccess file and look for these lines

Options +FollowSymLinks
RewriteEngine On

2) Underneath these lines:

301 Redirect Everything to new URL

RewriteRule ^(.*)$ http://www.new-domain.co.uk/$1 [R=301,L]

301 enforce WWW to URL

# Everything that does not start with wwww
RewriteCond %{HTTP_HOST}   !^www     [NC]
RewriteRule ^(.*)$          http://www.domain.com/$1  [L,R=301]
Tags: , , .

Leave a Reply

You must be logged in to post a comment.