05.14.07

How To Use .htaccess 301 Redirect

Using .htaccess to redirect your visitors from one page to another is the cleanest fastest way of making a redirect. This is the same method I use to redirect readers of this blog from DavePit.com to DavidPitlyuk.com. I do this because DavidPitlyuk.com may be too hard to spell, so I added DavePit.com which [...]



How To Use .htaccess 301 Redirect

Using .htaccess to redirect your visitors from one page to another is the cleanest fastest way of making a redirect. This is the same method I use to redirect readers of this blog from DavePit.com to DavidPitlyuk.com. I do this because DavidPitlyuk.com may be too hard to spell, so I added DavePit.com which is easy, and added a simple re-direct to move the readers over to the correct domain.

You can use .htaccess to redirect entire domains, folders, specific files, and more. John Chow uses an .htaccess redirect to set his preferred domain, something that can better your site from an SEO standpoint. I’ll go over how to do this as well.

Things To Note

Keep in mind that .htaccess is only supported on non-Windows servers, so any of you guys using Windows need to utilize another method to redirect your users. Also, if you are creating the .htaccess file in Windows, you’ll find that it doesn’t like filenames with no name on it. The workaround for this is to make the file something like htaccess.txt, and after uploading the file, rename on the server. Make sure to change http://www.example.com to your own domain name in any of the examples.

So let’s go over a few common methods of using the redirect:

Redirect An Entire Domain

This is what I use to redirect everybody who accesses this site at DavePit.com and transfer them to DavidPitlyuk.com.

Redirect 301 / http://www.example.com/

Redirect non-WWW to WWW (example.com > www.example.com)

This is the setting the preferred domain that I was talking about earlier. It will redirect all of your traffic at the example.com level and transfer it to www.example.com

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Redirect A Single File Or Folder

This will be used if you want to redirect something like http://www.example.com/blog2 to http://www.example.com/blog or http://www.example.com/blog.php to http://www.example.com/blog.

Redirect 301 /OldPageOrDirectory.html http://www.example.com/NewPageOrDirectory.html

There are many other methods of using .htaccess to redirect, but in the most cases this will cover what you need.

Save / Promote This Post

If you enjoyed this post, your vote is always highly appreciated!!


  1. Sohel Taslim

    12/05/2007 9:40 pm

    To use .htaccess in windows server you need to enable
    mod_rewrite.so

    Sohel Taslim



  2. DuseWreree

    03/31/2008 7:20 pm

    Yo!
    Wasjust serfing on net and found this site…want to say thanks. Great site and content!



  3. Fedir

    09/23/2008 12:29 pm

    Thanks, nice article :)



Add a Comment

Note: We use Gravatars, they are little icons that appear next to your name on this site and on many others. You can get a Gravatar account for free and any other site that supports it will show your avatar too!

Trackbacks



Projects

  • Manufacturer and reseller of aftermarket car parts

  • IT solutions based out of Maryland. From homeusers to mid-sized businesses.



Recent Comments

  • Caleb: I have an update to my EPN situation finally. Check it out ...
  • Brian: This is why it pays to Google yourself every now and then. T...
  • David Pitlyuk: Anthony - Very cool that I did in fact spot it then! I have...
  • Anthony Carbone: David, awesome exotic car spotting while in Monaco! That...
  • Fedir: Thanks, nice article :)...

About

My name is David Pitlyuk and I’m an entrepreneur. I’m always on the lookout for the next big opportunity. This blog hits topics of interest for entrepreneurs, as well as my miscellaneous ramblings.

Read more at the about page
RSS


Design: dpitMedia

©2008 David Pitlyuk