Skip to Content

Aarron Walter

XHTML | CSS |

Categories

My Book: Building Findable Websites

Building Findable Websites: Web Standards, SEO, and Beyond
Building Findable Websites: Web Standards, SEO, and Beyond
Aarron Walter
Buy on Amazon
Book's Companion Website
Companies waste fortunes seeking a magic bullet for Search Engine Optimization. But the keys to honest, effective web findability are appropriate writing and semantic markup. Aarron Walter’s wonderfully lucid and informative book tells everything you need to know to get your web content (or your client’s) in front of as many appreciative readers as possible.

- Jeffrey Zeldman, founder, Happy Cog Studios author, Designing With Web Standards, 2nd Edition

Now playing on my computer

Gnarls Barkley – Transformer Track | Artist
Frank Sinatra – You Make Me Feel So Young Track | Artist
Band of Horses – Is There a Ghost Track | Artist
B.T. Express – Do It ('Til You're Satisfied) Track | Artist
Rufus Wainwright – Harvester of Hearts Track | Artist
My Playlist Feed | My Last.fm Profile

Recent Photos From Flickr

Lincoln Balogna and Washinton Cheese, Sat, 2 Aug 2008 12:58:15 -0800 George Washington Cheese, Sat, 2 Aug 2008 12:55:09 -0800
Abe Lincoln Balogna, Sat, 2 Aug 2008 12:51:37 -0800 So many choices, Thu, 17 Jul 2008 15:11:20 -0800
My Flickr Photo Stream | All Photos

Running Two Domains On One Shared Hosting Server

15 Jan . 2007

Most people run their web sites on one of the many inexpensive shared hosting servers running a LAMP environment. If you are like me, you probably have a number of domain names registered, perhaps all parked on the same server pointing to the same site. It would be great to split things up, though, to point one domain to a particular site on your server, and other domains to their own site. Apache lets you do this using a special .htaccess file, which configures the server software on the fly. You can set up unique sites in their own directory on your server, and then
direct Apache to point requests for a particular domain to that folder. Let’s assume the domain you want to redirect is called “somedomain.com”, and the folder on your server where the site files reside is called “somedomain”. Create a plain text file with a text editor and add the following to it:

RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} somedomain.com
RewriteCond %{REQUEST_URI} !somedomain/
RewriteRule ^(.*)$ somedomain/$1 [L]

If you are on a Mac or Linux machine, you will need to save the file as something like htaccess.txt so the operating system does not hide the file (.htaccess is a special name the operating system recognizes, and will try to interpret the commands within). Upload the file to the root directory on your server (sometimes called, htdocs, public_html, or www among other names). Rename it .htaccess, then try accessing somedomain.com in a browser. It should direct your request to the files within the somedomain folder transparently, giving the effect of multiple domains with their own site running on the same shared hosting environment.

6 Responses to “Running Two Domains On One Shared Hosting Server”

  1. Chris Boudy Says:

    Hi Aarron, (Chris here again)

    Just wanted to ask a question about this method. Would this work with multiple domain name on the same server? For example, let’s say I added

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    RewriteCond %{HTTP_HOST} mydomain.com
    RewriteCond %{REQUEST_URI} !mydomain/
    RewriteRule ^(.*)$ mydomain/$1 [L]

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    RewriteCond %{HTTP_HOST} anotherdomainihave.net
    RewriteCond %{REQUEST_URI} !sanotherdomainihave/
    RewriteRule ^(.*)$ anotherdomainihave/$1 [L]

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    RewriteCond %{HTTP_HOST} a3rddomainihave.org
    RewriteCond %{REQUEST_URI} !a3rddomainihave/
    RewriteRule ^(.*)$ a3rddomainihave/$1 [L]

    to my .htaccess file. Would this work or is it only for two?

    Thanks

  2. Aarron Says:

    You have the general idea here, but you should be able to abbreviate it as follows:

    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    RewriteCond %{HTTP_HOST} mydomain.com
    RewriteCond %{REQUEST_URI} !mydomain/
    RewriteRule ^(.*)$ mydomain/$1 [L]

    RewriteCond %{HTTP_HOST} anotherdomainihave.net
    RewriteCond %{REQUEST_URI} !sanotherdomainihave/
    RewriteRule ^(.*)$ anotherdomainihave/$1 [L]

    RewriteCond %{HTTP_HOST} a3rddomainihave.org
    RewriteCond %{REQUEST_URI} !a3rddomainihave/
    RewriteRule ^(.*)$ a3rddomainihave/$1 [L]

  3. Jaunty Says:

    I used your method before and it worked. But I’m trying it again after reseting my servers and it’s not working.

  4. CJ Says:

    I read your Building Findable Websites book and was very pleased to learn new strategies to incorporate into the sites that I build. I was hoping that you covered htaccess settings in your book, but I could not find it. I just used code like the following to move the location of a page but after this change, the Google page rank fell from 3 to 0.

    redirect 301 /old/old.htm http://www.you.com/new.htm

    Is this temporary? Is there an SEO best practices method for relocating/renaming a file or set of files? I was trying to avoid the refresh meta tag.

    Follow up question - is it too risky to change the name of a file to a more search engine friendly name - say from booksale.htm to book-sale.htm?

    Thanks for any feedback!

  5. Aarron Says:

    @CJ - Chapter 3: Server-Side Strategies covers various htaccess concepts (mod_rewrite for search engine friendly URLS, 301 redirects, etc/), but it’s by no stretch a comprehensive examination of the subject. You might want to check out http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/ for a nice reference of common mod_rewrite solutions.

    A properly executed 301 redirect will communicate to search engines that a page has moved, and the ranking associated with it should be transferred to the new page. Maybe you executed your 301 redirect improperly? Here’s a quick example of how it should be done:

    # Redirect to new contact page
    RewriteEngine On
    RewriteRule ^contact.html(.*)$ /contact.php [L,R=301]

    This is the safest way to redirect pages without losing PageRank. You should also update your sitemap.xml file when your site changes structure and ping the various search services that support it so they will index your site properly (see the free chapter on the book’s companion site at http://buildingfindablewebsites.com/d/chapters/10_BFW.pdf for guidance with this).

    “Is this temporary?” - That depends on your perspective. Although you can incur a slight speed hit when you have a lot of redirects (your server has an extra step in order to point users to the right content), it really is not a problem to keep your 301 redirects live for a long time. Redirects are not really something you would take down after a month or a year as some users may still have the old URL bookmarked, and would get a 404 page if you removed the redirect. But when search engine spiders see a redirect they will update the indexes accordingly, and begin to point traffic to your new page. In that sense it is temporary, but I don’t recommend removing your redirects until you are absolutely certain they are no longer of any use.

    Changing filenames is not risky if you use redirects to point requests for the old URL to the new one. Plan URLs intelligently when you build a site, and hopefully you won’t find yourself having to make so many changes.

  6. TK Says:

    This works a treat, but I have been having endless problems trying to have both of my sites then share the same image folder (as there are many images common for both) for one of the domains created as above. My images folder is called ‘imgs’ and sits in the initial domain folder ‘mydomain/imgs’.
    Think i must be close, but just can’t get it to work from a number of varying scripts below (which are added below the initial setup for the domains - also tried adding variations above)

    A solution would be greatly appreciated!!

    Some of the scripting I have tried without success are:

    RewriteCond %{HTTP_HOST} a3rddomainihave.org
    RewriteRule ^imgs/([^/\.]+)/?$ /mydomain/imgs/$1 [L]
    #
    RewriteRule ^a3rddomainihave/imgs/([^/\.]+)/?$ /mydomain/imgs/$1 [L]
    #
    RewriteCond %{HTTP_HOST} a3rddomainihave.org
    RewriteRule ^imgs/([^/\.]+)/?$ http://www.mydomain.com/imgs/1 [L]
    #
    RewriteRule ^http://www.a3rddomainihave.org/imgs/([^/\.]+)/?$ http://www.mydomain.com/imgs/1 [L]
    #
    RewriteCond %{HTTP_HOST} a3rddomainihave.org
    RewriteRule ^imgs/([^/\.]+)/?$ /path/to/mydomain/imgs/$1 [L]

Share Your Thoughts

* indicates required