PDQ Library:  Redirecting Web Page URLs

Visitors can arrive at your website using URLs (web addresses) that begin with either http://YourSite.com or http://www.YourSite.com. It may sound odd, but Google will assign a separate page ranking for each of these URLs. Redirecting all web requests to the longer version of the URL prevents this problem. It also makes analyzing your web page statistics much simpler.

Redirect requests for YourSite.com to www.YourSite.com

To redirect requests for the short URL to the long form, all you need to do is add a few commands to a file in your website root directory called .htaccess. This file may already exist but you cannot see it because files that begin with a period are normally hidden. You will need to make it visible in your FTP software, usually by checking "show hidden files" in the options.

Download and edit the existing .htaccess file in a plain text editor such as Notepad. If you do not have an existing file, create a new one in your text editor. The contents of .htaccess may look something like this:

<Files ~ "^.(htaccess|htpasswd)$">
deny from all

Add the redirection commands below immediately after the line containing </Files>. Then replace only the characters YourSite.com to your domain name. Do not change any other characters!

RewriteEngine On
rewritecond %{http_host} ^YourSite.com
rewriteRule ^(.*) http://www.YourSite.com/$1 [R=301,L]

Save the file as .htaccess. If you are using an editor that can't save file names of this form, then name it something else, upload it and use your FTP software to rename it to .htaccess.

Redirecting Requests for Moved Files

Edit the .htaccess file in the root directory of your website as described above.

The example command below will redirect all requests for http://www.yoursite.com/old/file.html to the same file which was moved to a new subdirectory http://www.yoursite.com/new/file.html. This is an alternative to a "This page has moved" page, and far better than an "Error 401" (file not found).

Edit the old and new paths in this domain of the page. Then edit the new path or URL of the location it has moved to. Do not change any other characters. You can add as many redirection lines as you like, each one on a separate line.

Redirect permanent /old/file.html http://www.yoursite.com/new/file.html
Save the file as .htaccess and upload to your website. Now, when someone requests the original URL, it will automatically be redirected to the new location.

TOP back