301 Redirect non WWW. URLs to WWW. Urls

How to instructions using a 301 redirect and mod_rewrite


Simply enter the following code into your .htaccess file (changing the addresses in the examples below as needed) and save the changes. If there are several individual pages which have moved, just repeat as neccesary

301 Redirect non WWW. to WWW. Method 1:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

 

301 Redirect non WWW. to WWW. Method 2:

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

 

301 Redirect from WWW. to non WWW domain address

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]

  • 10 Users Found This Useful
Was this answer helpful?