How To Use The .htaccess File To Redirect Users
The purpose of this guide is to teach you how to use the .htaccess file to redirect users to pages that you have modified, deleted, or moved. The .htaccess file is associated with Apache Servers. Not all web hosting services allow modification of this file. Before following this guide, contact your web hosting service provider to confirm that addition and/or modification to this file is allowed.
- Access your site using the method you normally use to implement changes, and determine whether or not your directory includes a file named .htaccess
- If it does, open the file in the text editor of choice. (If so, Skip to step 5)
- If it does not, you will need to create one, and upload it to the Root Directory of your site. To do this, open up Notepad or your preferred text editor.
- Click File ---> Save as...
In Notepad, change the Save as type to All Files. Give your file the name .htaccess (the period "." before htaccess is required) and save it to the directory of your choice. Close the file.
- Now, open the .htaccess file with the text editor of your choice, and in one complete line, enter the commands for your desired effect, with a space between each command:
The redirect command has the following format: redirect status /old/old.html http://www.new.com/new.html
- "Status" is optional and may be one of the following:
permanent or 301 resource has moved permanently.
temp or 302 resource has moved temporarily.
seeother or 303 resource has been replaced.
gone or 410 resource has been permanently removed. (When this status is used the new-url argument should not be used.)
- Save the file, and depending on if it previously existed in the web directory or if you created it, update your site.
NOTE: If you created the file, it is important that you upload the file to the Root Directory of your site, which is the directory where your default "index" or "home" page resides.
1. Be sure not to add "http://www" to the first part of the statement - just put the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:
redirect 301 (the instruction that the page has moved)
/old/old.html (the original folder path and file name)
http://www.new.com/new.html (new path and file name)
2. Each page being redirected needs to occupy it's own line in the .htaccess file.
Be sure to test out your changes after you make them. If something does not work as intended, delete the entry, so it does not create any further problems, and refer to your web host for answers.