// you’re reading...

Search Engines

How to Setup and use 301 Redirects in a .htaccess file

Anytime a file or directory is deleted from a Website a 301 redirect should be setup within an .htaccess file. This is the proper way to seamless redirect all visitors and Search Bots to the new location.

If you fail to setup a 301 Redirect the document or directory will not be found, creating a 404 Error. When the Search Engines encounter the 404 Error long enough, they will remove the resulting page and any possible traffic you gained from the listing.

A few key factors to note:

  • Always double check your changes each time you upload the htaccess file. A miss-configured .htaccess file can totally break a Website. Not to worry, if you do break your Website simply delete the .htaccess file or upload a blank copy.
  • If you can’t create a .htaccess file on your PC or ftp Client, try naming it .htaccess.txt. Then once you upload the file, rename it to .htaccess.
  • When you upload the .htaccess file make sure you upload it in ASCII Mode. Uploading the file in Binary Mode will probably cause errors, breaking your Website
  • Some FTP Clients HIDE the .htaccess files. If this happens try the free FTP Program FileZilla.
  • Sometimes when you upload a .htaccess file you can’t see it even with FileZilla. This could happen if the hosting company has it hidden. You should be able to upload over the file, but you can’t see, select, or delete the file from the Server. Some hosts will make it visible if you ask.
  • Before you start working on .htaccess files it’s always best to test them in a sub-directory. If something doesn’t appear to work or works differently, ask your Hosting Company Support for help.
 

Copy between the /* start and end */ of the comment marks.

Move a single file or an entire directory.

/* start */
Redirect 301 /old-page.html http://www.adultwebmasterskills.com/new-location.html
Redirect 301 /directory/ http://www.adultwebmasterskills.com/new-directory/
/* end */

Redirect wordpress Feed URL to Feed Burner.

/* start */
Redirect 301/feed http://feeds.feedburner.com/AdultWebmasterSkills
/* end */

Move an entire Website to a new Domain.

/* start */
Redirect 301 / http://www.some-other-domain.com/ http://www.some-other-domain.com/</a>
/* end */

Redirect one file extension to another, carrying through the file name.

/* start */
RedirectMatch (.*)\.gif$  http://www.adultwebmasterskills.com$1.jpg/ http://www.adultwebmasterskills.com$1.jpg
RedirectMatch (.*)\.html$ http://www.adultwebmasterskills.com$1.php
/* end */

Redirect random added on file file variables/garage to the proper page.

/* start */
RedirectMatch 301 /info.html(.*)http://www.adultwebmasterskills.com/info.html
/* end */

Redirect affiliate links/variables to new page passing the values through.

/* start */
RedirectMatch 301 /old-page.php(.*)http://www.adultwebmasterskills.com/new-location.php$1
/* end */

Redirect www to the non-www version of a Website.

/* start */
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.adultwebmasterskills\.com/$
RewriteRule ^(.*)$ http://adultwebmasterskills g.com/$1 [R=permanent,L]
/* end */

Sample 2: Redirect www to the non-www version of a Website.

/* start */
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^ adultwebmasterskills \.com
RewriteRule (.*) http:// adultwebmasterskills.com/$1 [R=301,L]
/* end */

Redirect non-www to the www version of a Website.

/* start */
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^adultwebmasterskills\.com/$
RewriteRule ^(.*)$ http://www.adultwebmasterskills g.com/$1 [R=permanent,L]
/* end */

Sample 2: Redirect non-www to the www version of a Website.

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

Dealing with the .htaccess file and all its various rules can be a real pain. The best advice I can give is to make sure you fully test your changes as you make them. And finally, if something in the .htaccess file appears it should be working, but doesn’t then try finding another example online to test, after a few attempts you should find an example that works for you.

If you would like to test your 301 redirects try this free online HTTP Status Checker.

Pass it On:
  • Add to favorites
  • Google Bookmarks
  • Twitter
  • StumbleUpon
  • FriendFeed
  • del.icio.us
  • Digg
  • Sphinn
  • Mixx

Comments are closed for this post...

Sorry, comments are closed... if you would like to comment then please contact me directly with your comment.

When you subscribe to the FREE "Adult Webmaster Skills Monthly" you'll discover,
  • The 5 Industry Secrets...
  • The Truth to Converting Traffic!
  • The Secret Industry System You Can Use Today.
  • And Free Access To The Subscribers Only Area!
Select a Username and enter your Primary Email Address Below...
Username:
* Email:
A password will be e-mailed to you.

* Please check your primary email address for accuracy to ensure you receive your password for access. I respect YOUR email privacy
and I will NOT rent, trade, sell or release your name or email to any third party for any reason - ever.