Redirect www to non www and the reverse in .htaccess – works

I always have trouble remembering the proper way to redirect my www.craigryder.com to craigryder.com so in the spirit of me posting stuff here so I won’t forget it, here it is.

Redirect www to non-www:

RewriteEngine On
RewriteBase /
RewriteCond % ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301

Redirect non-www to www:

RewriteEngine On
RewriteBase /
RewriteCond % ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

It is important to understand that there is a difference to the search engines between https://craigryder.com and https://www.craigryder.com . I will go into this more later or if anyone requests more info.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.