.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
Redirect /safe https://www.massiveblue.comRedirect /shop https://www.massiveblue.com/shop- Download this code: /code/htaccess_redirect.txt
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:
Redirect /map.html http://site.com/map/ [or]Redirect /download.html http://site.com/files/download.html- Download this code: /code/htaccess_redirect2.txt
Removing [or] from the above example of course.
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!