When building a website or blog, you need to decide how people will link to you. Either with www prefix or without www. Some peoples love to have www in front of their domain name but some are don’t.
Both of the them does not have pro or con. But it is better for you to choose one and stick to it. This is because we don’t want to get penalised by Google for content duplicates.
no-WWW to WWW
As for myself, I am using with www prefix for my domain. I feel it is more professional to have www in front of my domain but some don’t think like that. To redirect your website from non www to www prefix, you need to put these lines in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cypherhackz.net$
RewriteRule ^(.*)$ http://www.cypherhackz.net/$1 [R=301,L]
As you can see here, the RewriteCond is to check the url. If the url is http://cypherhackz.net/any/posturls/ which is the condition is true, it will redirect you to www prefix like this http://www.cypherhackz.net/any/posturls/.
WWW to no-WWW
But if you prefer without www prefix, just twist the above code like this.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.cypherhackz.net$
RewriteRule ^(.*)$ http://cypherhackz.net/$1 [R=301,L]
BTW make sure to replace my domain with yours or it will not work. Hope this helps!
Extra Tip: Using WordPress? There is a Wodpress plugin that will automatically do this job. You just need to install the plugin and activate. It is very easy!
Syahid Ali says
This is what happen to gua.com.my and http://www.gua.com.my last time. but this has been fixed now.
Jae Jun says
Sweet. Did the trick.
scorpio2k2 says
thanks. verry useful