Redirect site to www or non www

From Brian Nelson Ramblings
Jump to: navigation, search

Redirect site to www or non www

Some times, you are going to need to redirect your domain name to have www or whatever and sometimes you will want to strip the sub domain out.

When running a magento store, you will come across a need for this, as their default redirect only redirects to the homepage if the request is not the same as their base_urls.

Redirect Entire site to WWW

How to force all url strings to load from www

Add the following to your .htaccess file, at the top saying, if it does not start with www redirect it.

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

Redirect Entire site to non-WWW

How to force all urls to come directly to your domain name

Add the following to your .htaccess file, at the top

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