Skip to content

Tame Multiple Domains On The Web Site With htaccess 301 Redirect

December 20, 2008 by dashaver

.htaccess 301

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

Is the domain name runillinois.org pointed at psrunner.com?

November 10, 2009 by Jules (not verified), 2 years 12 weeks ago
Comment id: 618

Thanks for writing the article, it's just what I was looking for. I'm a little fuzzy about the domain and hosting in the background. Is the domain name runillinois.org pointed at psrunner.com? I wasn't sure if it was possible to point two domain names at one hosting package or if you had to have a separate hosting package for the alternate domain.

I appreciate the clarification. Thanks!

runillinois.org is the

November 11, 2009 by dashaver, 2 years 12 weeks ago
Comment id: 619

runillinois.org is the original domain; the others are changes since then. You can have several domains which point to the same website. The htaccess changes them all to psrunner.com it all the same hosting package. One of the most important things to be at the top of a search for your terms is to prevent duplicate content

http://en.wikipedia.org/wiki/Htaccess

Some ftp software will show

October 5, 2009 by dashaver, 2 years 18 weeks ago
Comment id: 507

Some ftp software will not show .htaccess files. You will need to find the option to show hidden files and change it.

Actually you should upload

October 3, 2009 by dashaver, 2 years 18 weeks ago
Comment id: 502

Actually you should upload this file as htaccess.txt and change it to .htacess after it is uploaded. This is because some ftp software may upload it as binary instead of ascii. If it is uploaded in binary it will not work for its intended purpose. If is uploaded as a txt (text file) it will be in ascii and not be corrupted.

tres useful! cheers

June 26, 2009 by newtoid (not verified), 2 years 32 weeks ago
Comment id: 224

tres useful! cheers

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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

By submitting this form, you accept the Mollom privacy policy.
D. A. Shaver Web Design

Back To The Top Of This Page