The smoothest way to redirect your visitors is to use an .htaccess redirect. This has no delay since before a page is served to the browser the server checks first for an .htaccess file... if it sees this the old page never loads, instead visitors are sent directly to the new page.

These are a few .htaccess redirect codes that I've used that might come in handy for you. This is not a complete list by any means, but it took me ages to find how to do these so I'll save you the hassle and list them here. Oh, and please don't email me with questions about how these work, like I said, I found these with the help of others.. I have no idea in the slightest how to write this stuff and take no credit (or responsibility) for how they work.

If you're more technically minded than I am and want the information straight from the source, check the Apache Tutorial: .htaccess files for more detailed info.

Important notes about htaccess redirection
  1. Always be sure to upload .htaccess files in ascii mode, sending it up as binary will break it (and usually make your server very, very unhappy.)
  2. .htaccess does not work if you're on a windows server.
  3. Make sure you triple check your changes. Clear your cache and look, test the server headers to make sure you see a 301 (that means its permanent) not a 302 (temporary) unless you are absolutely sure you really mean temporary.
  4. Since some operating systems don't allow you to make a file without something before the "." you may need to save it as something.htaccess, some may even have to save it as htaccess.txt and change it once you've uploaded it.
  5. Make sure your ftp program will show .htaccess files (FileZilla does and is free) It is a bit hard to edit something you can't see
  6. Double check that you're not overwriting an old one (some servers already place one there for your custom 404 pages etc.)
  7. Make sure you replace example.com with your own sites URL ;-)

301 Redirect Examples
  • To Move a single page
    Code:
    Redirect 301 /oldpage.html http://www.example.com/newpage.html
  • To Move an entire site
    Code:
    Redirect 301 / http://www.example.com/
  • Changed file extension?
    Code:
    RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php
  • Redirect www to non www version of site
    Code:
    Options +FollowSymLinks 
    RewriteEngine on
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^example\.com
    RewriteRule (.*) http://example.com/$1 [R=301,L]
  • Redirect non-www to www
    Code:
    Options +FollowSymLinks 
    RewriteEngine on 
    RewriteCond %{HTTP_HOST} ^yoursite.com [NC] 
    RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
  • Redirect example.com/index.php to example.com/
    Code:
    Options +FollowSymLinks
    RewriteEngine on
    # index.php to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3, 9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]