Redirection

One of the most useful functions of the .htaccess file is to redirect requests to different files, either on the same server, or on a completely different web site. It can be extremely useful if you change the name of one of your files but allow users to still find it. Another use (which I find very useful) is to redirect to a longer URL, for example in my newsletters I can use a very short URL for my affiliate links. The following can be done to redirect a specific file:

Redirect /location/from/root/file.ext http://www.othersite.com/new/file/location.xyz

In this above example, a file in the root directory called oldfile.html would be entered as: /oldfile.html

and a file in the old subdirectory would be entered as: /old/oldfile.html

You can also redirect whole directories of your site using the .htaccess file, for example if you had a directory called olddirectory on your site and you had set up the same files on a new site at: http://www.newsite.com/newdirectory/ you could redirect all the files in that directory without having to specify each one:

Redirect /olddirectory http://www.newsite.com/newdirectory

Then, any request to your site below /olddirectory will bee redirected to the new site, with the extra information in the URL added on, for example if someone typed in:

http://www.youroldsite.com/olddirecotry/oldfiles/images/image.gif

They would be redirected to:

http://www.newsite.com/newdirectory/oldfiles/images/image.gif

This can prove to be extremely powerful if used correctly.

  • 0 istifadəçi bunu faydalı hesab edir
Bu cavab sizə kömək etdi?

Uyğun məqalələr

Introduction to htaccess

In this tutorial you will find out about the .htaccess file and the power it has to improve your...

Creating .htaccess File

An htaccess file is a simple ASCII file, such as you would create through a text editor...

Custom Error Pages

The first use of the .htaccess file is custom error pages. These will allow you to have your own,...

Password Protection

Introduction Although there are many uses of the .htaccess file, by far the most popular, and...

Powered by WHMCompleteSolution