How-to Guide: Redirects and htaccess

htaccess file in the main directory of your website. The base directory for a website is usually called something like htdocs...

provided by: 

By Bret Fencl, Fencl Web Design

Every time you turn around another article on the Internet tells you to make a 301 redirect for the obsolete pages on your website. The problem is that most of these articles do not explain how to make a proper redirect.

First Check for a .htaccess File
Check to see if you have a .htaccess file in the main directory of your website. The base directory for a website is usually called something like htdocs, httpdocs, www or public, and is the file where your home index page resides.
 
On many servers the .htaccess file may be hidden from FTP software, so you will want to try accessing it through your Web hosting file manager. If you still cannot find a .htaccess file, then check with your Web hosting company to make sure you do not overwrite it, which could damage your Web hosting or site.
 
If you find the .htaccess file, make sure you save a backup copy before making any changes to it.

Creating a .htaccess File
If you do not have a .htaccess file you will need to create one.

This is a basic text file and does not have any extension on the end of it. Simply create a new text file and name it .htaccess and save the file starting with a period(.).

Once you upload this file to your server it may become hidden or disappear. But don't worry, it will still function properly.

Creating a 301 Redirect
A 301 redirect is used to send a visitor that was trying to access an outdated page of your website to the new page. This also assists many search engine bots in finding the new page and dropping the old page from the index.

The command you would use in your .htaccess file is simply:
redirect 301 oldpage.html newpage.html

You may also use the same method to redirect visitors from an old file to a new page.
redirect 301 /oldfile/ newpage.html

Creating a 302 Redirect
A 302 redirect is used much the same as a 301 redirect but the difference is that it tells the search engine bots that this move is only temporary and the old page will be returning soon. This is particularly useful for retailers who may have run out of a product and will have it back in stock in a week so you temporarily point the page to a similar product to avoid losing sales.

For a 302 redirect, simply enter this code into your .htaccess file:
redirect 302 oldpage.html temporarypage.html

Creating a Mod Rewrite
Sometimes you can simply make a redirect by rewriting the name of a new page in the same file directory of a website without actually changing the page name your visitor's access. You need to check with your Web host to see if they allow mod rewrite - many Web hosting companies do.

For example, you have a product that you want to advertise on your website and send to your customers in an email newsletter. A long web address may break when you email a URL such as: http://www.example.com/index.php?cart=98234&id=4593921

Another need for this situation is that it may make it easier to explain the Web address over the phone or write it down for someone on the fly.

The above URL could be shortened to:
http://www.example.com/widget.php

Here is the .htaccess command for a Mod Rewrite on a URL:
Options +FollowSymLinks
RewriteEngine on
RewriteRule widget.php index.php?cart=98234&id=4593921


Redirects are important for websites to remain up-to-date and for the search spiders to consistently index fresh content. While this is simply a primer to .htaccess and redirects, and you may have to try a little experimenting, soon you will learn fun new uses for redirects and mod rewrite and make sure that your site never appears outdated.
 
 
Website Magazine

Read full article at websitemagazine.com
Regional Articles
- How-to Guide: Redirects and htaccess Alabama
- How-to Guide: Redirects and htaccess Alaska
- How-to Guide: Redirects and htaccess Arizona
- How-to Guide: Redirects and htaccess Arkansas
- How-to Guide: Redirects and htaccess California
- How-to Guide: Redirects and htaccess Colorado
- How-to Guide: Redirects and htaccess Connecticut
- How-to Guide: Redirects and htaccess DC
- How-to Guide: Redirects and htaccess Delaware
- How-to Guide: Redirects and htaccess Florida
- How-to Guide: Redirects and htaccess Georgia
- How-to Guide: Redirects and htaccess Hawaii
- How-to Guide: Redirects and htaccess Idaho
- How-to Guide: Redirects and htaccess Illinois
- How-to Guide: Redirects and htaccess Indiana
- How-to Guide: Redirects and htaccess Iowa
- How-to Guide: Redirects and htaccess Kansas
- How-to Guide: Redirects and htaccess Kentucky
- How-to Guide: Redirects and htaccess Louisiana
- How-to Guide: Redirects and htaccess Maine
- How-to Guide: Redirects and htaccess Maryland
- How-to Guide: Redirects and htaccess Massachusetts
- How-to Guide: Redirects and htaccess Michigan
- How-to Guide: Redirects and htaccess Minnesota
- How-to Guide: Redirects and htaccess Mississippi
- How-to Guide: Redirects and htaccess Missouri
- How-to Guide: Redirects and htaccess Montana
- How-to Guide: Redirects and htaccess Nebraska
- How-to Guide: Redirects and htaccess Nevada
- How-to Guide: Redirects and htaccess New Hampshire
- How-to Guide: Redirects and htaccess New Jersey
- How-to Guide: Redirects and htaccess New Mexico
- How-to Guide: Redirects and htaccess New York
- How-to Guide: Redirects and htaccess North Carolina
- How-to Guide: Redirects and htaccess North Dakota
- How-to Guide: Redirects and htaccess Ohio
- How-to Guide: Redirects and htaccess Oklahoma
- How-to Guide: Redirects and htaccess Oregon
- How-to Guide: Redirects and htaccess Pennsylvania
- How-to Guide: Redirects and htaccess Rhode Island
- How-to Guide: Redirects and htaccess South Carolina
- How-to Guide: Redirects and htaccess South Dakota
- How-to Guide: Redirects and htaccess Tennessee
- How-to Guide: Redirects and htaccess Texas
- How-to Guide: Redirects and htaccess Utah
- How-to Guide: Redirects and htaccess Vermont
- How-to Guide: Redirects and htaccess Virginia
- How-to Guide: Redirects and htaccess Washington
- How-to Guide: Redirects and htaccess West Virginia
- How-to Guide: Redirects and htaccess Wisconsin
- How-to Guide: Redirects and htaccess Wyoming
Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Educational Content Home Appliances Real Estate Resources
Business Services Entertainment Home Electronics Software
Career Family Home Services Technology
Cars Fashion Internet Telecommunications
Chamber of Commerce Financial Services Legal Trade Shows
Computer Hardware Franchise Miscellaneous Travel
Construction Health Nightlife Weddings
Education Holidays Online Database World History