First you have to create a file named .htaccess (note the leading dot) in your blog root directory. If you already have a sample.htaccess file which comes with b2evo, rename it to .htaccess
If you don't know what this file does, take a look at this manual http://httpd.apache.org/docs/1.3/howto/htaccess.html
Ok, let's start. In order to enable redirects you must put these 2 lines in top of the file.
RewriteEngine On
Options +FollowSymLinks
1. Then if you want to redirect all non-www requests to www copy the following code in .htaccess
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
2. If you want to redirect all www requests to non-www use the following
# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1 [R=301,L]
Thanks to ¥åßßå for the code snippets, you can also blame him if they don't work :)
sam2kb wrote:
Point worth noting: make absolutely certain you do not already have a .htaccess file before you create and upload one, or rename sample.htaccess!
Many FTP clients and host-provided file manager tools will hide files that begin with a dot, so be sure to check and set your method of viewing files on your server to show hidden files. Also be aware that many hosts will use .htaccess to take care of some of the things you can do from your cpanel (or other host interface tool). Things like hot-link enabling, IP banning, adding addon domains, and probably others are usually done by adding bits to your .htaccess file whether you can see that file or not.
Therefore it is in your best interests to first make sure if you do or do not already have that possibly hidden file, and if so to know that what you and your host add to it MIGHT conflict one day. ALWAYS have backup files!