Home > htaccess > .htaccess redirect

.htaccess redirect

The Redirect directive maps an old URL into a new one. The new URL is returned to the client which attempts to fetch it again with the new address.

I only just discovered today how easy, useful and effective .htaccess Redirects are. Here is the code in its purist form:
Redirect file.html http://your.url/file2.html

I have a few pages that I only wanted to be available through a secure connection, https. However, I needed a fail-safe just incase someone visited the URL on the non-secure server, http. This is where .htaccess comes in.

Redirecting folders

I added the following two lines to my .htaccess file in my root directory

  1. Redirect /safe https://www.massiveblue.com
  2. Redirect /shop https://www.massiveblue.com/shop

Pretty straight forward, this simply redirects in the above example http://www.massiveblue.com/safe/ to https://www.massiveblue.com. Easy!

Redirecting files

This can also easily be done for individual files. Instead of having to use the dated meta http-equiv="refresh" content="1;URL=map.html" method in the head tag we can use a .htaccess redirect that removes the need for the file in the first place, the code would look like the following:

  1. Redirect /map.html http://site.com/map/ [or]
  2. Redirect /download.html http://site.com/files/download.html

Creating a .htacccess file

Creating a htaccess file couldn’t be any easier. Simply open up TextEdit or Notepad for example type in your Redirect, or copy one from above and save the file as a htaccess.txt (plain text) file, no RTF. Upload the file to the root directory on your server and then rename the file to .htaccess that’s it!

Related posts:

  1. how-to-redirect-a-webpage
  2. Beginners Guide to .htaccess File with Examples
  3. Guide to htaccess and mod_rewrite
  4. Beginners guide to .htaccess file with examples – Part II
Categories: htaccess Tags:
  1. No comments yet.
  1. No trackbacks yet.