Apache .htaccess Guide, Tutorials and Articles
Username:
Password:
Register / My Account / Forgotten Password?

Redirects

(Edit this article)
Redirects enable us to direct web site visitors from one document within your web site to another. This is useful for example, if you have moved your web site content and would like to redirect visitors from old links to the new content location.

To set-up redirects, create a .htaccess file following the main instructions and guidance which includes the following text:

Redirect /old_dir/ http://www.yourdomain.com/new_dir/index.html

The above line tells the Apache Web Server that if a visitor requests a documents located in the directory 'old_dir', then to display the document 'index.html' located in the directory 'new_dir'.

You see in this example, the 'old_dir' is the location of the document to be requested by the visitor, and is a document or directory located under your main domain. In this example, the directory 'old_dir' would be located at 'http://www.yourdomain.com/old_dir/'. However, you will also notice the location of the file that the visitor is to be redirected to is a full web site URL, not what is referred to as a relative URL in the case of 'old_dir'. This means we can redirect visitors to the 'old_dir' folder to any web site document, it doesn't have to be held within your web site content and could be any web site.

It is very important (and the most common cause of error) that you understand the difference between a relative URL and an absolute/full URL. A relative URL is the location of the document within the web site, and does not include the actual domain name of the web site. These are used for documents held within the web site to simplify and shorten the URL. A absolute or full URL is one which includes the full domain name.

For example, for a absolute/full URL, 'http://www.yourdomain.com/directory/file.html'. the relative URL for this document would be, '/directory/file.html'.

<- Error documents Password protection ->

Visitor Comments and Responses

Moderator Article Rating: 10 out of 10
Padraic, was the 'All Files (*.*)' option available when saving? If so, select that then enter the filename '.htaccess'. Alternatively, save as a .txt file then rename the file in Windows (you may need to enable the display of file extensions) or failing that rename the file using your FTP software before or after uploading it.
Space Holder
Anonymous Article Rating: 10 out of 10
Does any one know how to create a framed forwarding rule in a .htaccess file? So the original URL stays in the browser address bar.
Space Holder
Padraic Article Rating: 8 out of 10
Hello thanks for all the help supplied here but can i just disagree with one point, I could not use Wordpad to save the .htaccess file, i could only save as a .txt, .rtf, unicode or DOS file but not as a .htaccess file. I also had to cancel the inadequate Hosting company forwarding.
Padraic

Space Holder
LeptOptogef Article Rating: 10 out of 10
I'’d prefer reading in my native language, because my knowledge of your language is no so well. But it was interesting!
Space Holder
Doodee Article Rating: 10 out of 10
Thanks for sharing!
Space Holder
Moderator Article Rating: 10 out of 10
Setup the 404 error document as explained in the previous article, then use a meta refresh tag to redirect the user after X second.
Space Holder
delay? Article Rating: 10 out of 10
any way to set a delay so that a 404 could be read then redirected?
Space Holder
Average Rating: 9.05 out of 10 (2799 Votes)

Submit Comment/Rating

Article Rating:
Name: (optional)
Your Comment/Response: (optional)
Powered by OpenCrypt Article Manager
Table of Contents RSS Feed
1. What is .htaccess?
2. How to use .htaccess
3. Error documents
4. Redirects
5. Password protection
6. Deny visitors by IP address
7. Deny visitors by referrer
8. Hot link prevention techniques
9. Blocking offline browsers and 'bad bots'
10. DirectoryIndex uses
11. Adding MIME types
12. Enable SSI with .htaccess
13. Enable CGI outside of the cgi-bin
14. Disable directory listings
15. Setting server timezone
16. Changing server signature
17. Useful Resources
Space Holder
Space Holder


Copyright © 1999 - 2008 ionix Limited. All Rights Reserved. Company Information, Affiliates

Powered by OpenCrypt Membership Software