WebSites-n-Services Google Sitemaps Knowledge Base Article 3

02/07/2006

using .htaccess to 301 Redirect

Topics:

Creating an .htaccess file

Formatting an .htaccess file

FTP Transfer settings for an .htaccess file

.htaccess code example for 301 Redirect

Security considerations for .htaccess and code example

Cheat Sheet for .htaccess codes

Problems with various code examples for 301 Redirect

 

Creating an .htaccess file:

    An .htaccess file is a simple text file. Only one method is listed here and it works.

    Create a file named .htaccess using a hex editor. Notice that there is no file name, the file is simply   .htaccess.  You may have trouble creating such a file in notepad or similar tools. Methods to compensate for that are not included here. Ultra Edit is an excellent hex editor and is reasonably priced at around $40 US.

    Imho, a hex editor is a must for any web developer. Hex editors generally support many formats which developers will work with, including XML, and will have the necessary features to create files such as .htaccess which require specific line terminators and encoding. For example, a robots.txt file, a neccessity for any web site, requires Unix line terminators and must be encoded UTF-8.  See also KB2.

 

Formatting an .htaccess file:

    .htaccess files need to be formatted with "default" or DOS line terminators.  The file must be encoded ANSI/ASCII.

 

FTP Transfer settings for an .htaccess file:

    .htaccess must be transferred in ASCII mode. Check your program's FTP settings before uploading the file. The default mode on most FTP programs is Binary.

 

.htaccess code example:

Redirect 301 /index.htm http://www.abc.com/index.php
Redirect 301 /graphicart.htm http://www.abc.com/graphicart.php
Redirect 301 /webdesign.htm http://www.abc.com/webdesign.php

 

Security considerations for .htaccess and code example:

    Access to the .htaccess file should always be restricted, failure to do so can result in a complete security breach of your domain, exposing your passwords, etc.. to the world.

    The code to restrict access to the .htaccess file is as follows and should be placed at the very top of the file:

<files .htaccess>
order allow,deny
deny from all
</files>

 

Cheat Sheet for .htaccess codes:

    There are many resources for finding additonal .htaccess codes. Here is a link to a good site for a cheat sheet.

 

Problems with various code examples for 301 Redirect:

    I had quite a bit of trouble getting the correct code to for 301 Redirect. I found that the example for redirecting
an entire directory, instead of the example for moving individual pages, was what worked for me.

 

 

Check for Updates to this Article

Click here if you have a correction for this page or updated information

Directory of KB Articles

Visit WebSites-n-Services