Skip to content

Tame Multiple Domains On The Web Site With htaccess 301 Redirect

December 20, 2008 by D. A. Shaver

I wanted to add Google Maps to www.psrunner.com however over the years I have accumulated three domains pointing to this web site. To get the Google Maps Developer key you need to have one for each domain. My first plan was to get multiple developer keys and write a JavaScript program to present the right key depending on which domain the user had used to get the web site.

From a search engine point of view multiple domains for one web site are a problem because it leads to duplicate content in their index (2 listings for the same page).

In addition if I wanted to get another application that would mean another JavaScript program to present the correct developer key.

It finally occurred to me that I needed to solve the problem before that. Enter htaccess. This is a program, which would be there ready to run on the server when the web site is requested. So I made this file that looks at the incoming requests for the web site and if the two old domains are requested it changes them to the domain I want to use and giving a 301 Redirect. This is great because it tells the search engine the page has permanently moved to the new domain. All links and shortcuts everywhere will still work, they will just be changed to the new domain when they get to the web site. So if you type in http://prairiestaterunner.com/ your will get http://www.psrunner.com/ it also adds the www if you do not which also removes duplicates from the search engine index. This makes the htaccess solution a win-win for everybody.

If you want to add an htaccess 301 redirect to your web site here is how. First make sure your ftp software is set up to show hidden files. It will be in the public_html directory and the period before the h is required and the h is in lower case. htaccess files are often hidden on the server. Next if you already have one download it and copy it as a backup. Open it in a text editor such as notepad. If you do not already have one open up notepad and save it as . htaccess next add the following.

Options +FollowSymLinks

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?runillinois\.org [NC]

RewriteRule ^(.*)$ http://www.psrunner.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)?prairiestaterunner\.com [NC]

RewriteRule ^(.*)$ http://www.psrunner.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^psrunner\.com [NC]

RewriteRule ^(.*)$ http://www.psrunner.com/$1 [R=301,L]

The bottom two lines add the www if it is not already present. If you have more than two old domains you could add another pair of lines using the same pattern shown. Just upload this file to your public_html directory and make sure it works ok. You did save a copy of your old htaccess didn’t you?

http://httpd.apache.org/docs/1.3/howto/htaccess.html

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

This blog uses the CommentLuv Drupal plugin which will try and parse your sites feed and display a link to your last post, please be patient while it tries to find it for you.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
5 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Drupal Web Sites

Drupal Hosting

Custom Drupal Business Blogs & Web Sites Starting at $175 with your hosting account

http://www.dashaver.com/contact

D. A. Shaver Web Design

Back To The Top Of This Page