How to Redirect to the WWW or non-WWW version of your Domain


Step 1 - Access and edit your .htaccess file. Click here for a guide if you're unsure how to do that.

Step 2 - Add the following code to the top of your .htaccess, depending on whether you want to force the use of 'www.' or not. (Update 'yourdomain.net.au' with your real domain name.)

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.net.au [NC]
RewriteRule ^(.*)$ <a href="<a href="http://www.yourdomain.net.au/%241">http://www.yourdomain.net.au/$1</a>"><a href="http://www.yourdomain.net.au/%241">http://www.yourdomain.net.au/$1</a></a> [L,R=301,NC]
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^<a href="<a href="www.yourdomain.net.au">www.yourdomain.net.au</a>"><a href="www.yourdomain.net.au">www.yourdomain.net.au</a></a> [NC]
RewriteRule ^(.*)$ <a href="<a href="http://yourdomain.net.au/%241">http://yourdomain.net.au/$1</a>"><a href="http://yourdomain.net.au/%241">http://yourdomain.net.au/$1</a></a> [L,R=301]


Thank you for your feedback on this article.