My Web Hosting Manual


Home > .htaccess > Redirects

Redirects

Imagine you have a file named: jasons-idea-of-a-god-time.html

After some time you realize that its wrong and you want to change it to jasons-idea-of-a-good-time.html. What would happen to all the people who bookmarked the page and everyone finding the page via a search engine? Don't worry. With a simple redirect the problem can be solved.
This feature is very useful if you redisign and relocate files on your site.

The Apache web server provides several ways for setting up redirects for different reasons.

The most simple one is using the “Redirect” directive:

Redirect /oldfolder http://www.domain.com/newfolder

If you include this line in your .htaccess file, a visitor trying to go to http://www.domain.com/oldfolder will be automaticly redirected to http://www.domain.com/newfolder with out him ever knowing it.

Since the search engines get tougher everyday, now we have "permanent redirects" too. The status code of a permament move is 301. In .htaccess it would be something like this:

Redirect permanent /oldfolder http://www.domain.com/newfolder

Another useful use is the RedirectMatch. With it you can use regular expressions in the redirect condition. For example:

RedirectMatch "\.html$" http://www.domain.com/index.php

In this case, this line of code will redirect any and all visitors looking for a .html file into a .php file. When can this happen? Say you start your website with a regular .html file. In time, youll probably get somewhat familiar with CMS (Content Management System) that used PHP. Your pages would no longer be .html, they would end in .php. All bookmarks would suddenly work again.

There is another way, more powerful and more complex called ModRewrite, but we will talk about it later.

Review It

You might also be interested in:






Top Hosting
  - Host Gator
  - Host Monster
  - Blue Host
  - Easy CGI
  - Lunar Pages
       
All content has been created by Juan Carlos Gorospe. These are my opinions and experiences.
Copyright © 2008, Juan Carlos Gorospe. All Rights Reserved.