Two domain names on one account?

Two domain names on one account?

Posted by: Erichero
Posted on: 2009-01-21 01:26:00

I'm fairly new at this and just want to understand correctly. I've used the Dreamhost panel a little bit and I've done some fiddling before with HTACCESS.

We have an existing website that is primarily on Rails and provides HTACCESS rewrite exceptions for some PHP plugins.

We have just registered a second domain name (url) with Dreamhost and would like it to point to a certain section of the existing site (existing account).

So the old domain would be: www.mysite.com/section/somepage
This needs to rewrite to: www.new.com/somepage

So there's two issues here: those who come in on new.com must only see new.com, but the underlying reading/writing still deals with mysite.com. Secondly, those who come in from an old link must see the same page but see new.com in the address bar.

Can it be done and how do I achieve this?

Re: Two domain names on one account?

Posted by: Erichero
Posted on: 2009-01-21 01:29:00

And I should add that the other sections of the old site must read as before.

So in my example, only www.mysite.com/section gets a rewrite, but all other parts of www.mysite.com read as before.

Re: Two domain names on one account?

Posted by: Erichero
Posted on: 2009-01-29 08:20:00

Can anyone help with this?

Re: Two domain names on one account?

Posted by: Atropos7
Posted on: 2009-01-29 08:54:00

In reply to:

So the old domain would be: www.mysite.com/section/somepage


Uhm, does www.mysite.com/section map to a physical directory or is it virtual?

If its physical, ie /home/username/mysite.com/section/somepage.rb, then you could specify the directory as the web directory for new.com, then just have to re-write the filename if necessary.

In reply to:

Secondly, those who come in from an old link must see the same page but see new.com in the address bar.


If the above works for you, then you could redirect to new.com based on the HTTP_HOST header.

I don't do any RoR programming yet, so don't know why you can just deploy whatever mysite.com/section did into the web directory for new.com instead. Do the domains have different FTP/CGI runs-as users?



cool openvein.org -//-

Re: Two domain names on one account?

Posted by: Erichero
Posted on: 2009-01-29 09:38:00

Thanks for the feedback. We basically have two domains that point to the same user account on Dreamhost (ie. the same physical directory, if I understand correctly).

I'm guessing that all I need to do is to add some rewrite rules in the HTACCESS file. In my example, www.mysite.com/section needs to be rewritten to www.newsite.com whenever it is encountered.

I assume that this will work? In other words, all the users will think they are on newsite.com (including search engine bots), when in fact the file system (web server) still acts like before.

Re: Two domain names on one account?

Posted by: Atropos7
Posted on: 2009-01-29 11:58:00

In reply to:

Thanks for the feedback. We basically have two domains that point to the same user account on Dreamhost (ie. the same physical directory, if I understand correctly).


Uh, not exactly what I was talking about.

DreamHost uses named-based virtual hosting. The browser connects to the DreamHost machine and tells the machine what hostname it is trying to visit. This is provided in the "Host" header of the requuest and becomes available on the machine as the HTTP_HOST environment variable.

HTTP requests also include a url-path. This is the part of the URI after the hostname (included the slash) but not the fragment or query string. eg http://example.com/index.php?page=home, the url-path here is /index.php

Now when a request comes into the Apache, it goes through the server configuration looking for special rules to apply to certain uri-paths. It will then traverse the filesystem for .htaccess files with special rules too (this is where mod_rewrite comes in). If no special rules apply, it translates the url-path to a filesystem path and attempts to access that directory or file (what I meant as 'physical') This file system path will be relative to the "document root" (DreamHost calls it the web directory" ie http://example.com/index.php gets mapped to /home/username/example.com/index.php given a web directory of /home/username/example.com

By 'virtual' I meant the 'search engine friendly' urls the like that are 'special', eg the url-path /show/picture/1 gets converted to a call to /index.php?action=show&category=picture&item=1 (which might be the cases if the url is handled by RoR apps too)

In reply to:

I'm guessing that all I need to do is to add some rewrite rules in the HTACCESS file. In my example, www.mysite.com/section needs to be rewritten to www.newsite.com whenever it is encountered.]http://I'm guessing that all I need to do is to add some rewrite rules in the HTACCESS file. In my example, www.mysite.com/section needs to be rewritten to www.newsite.com whenever it is encountered.


There are two different methods, two different words: redirect and rewrite. A redirect tells the browser to go to a different url. So that is what you need to ask for when you want the "address bar to change." A rewrite is where Apache changes the value and uses the new value instead - it doesn't have to tell the browser the value changed - so the "address bar does not change".

Again Now you want a redirect when:
browser asks for http://mysite.com/section/something
server tells browser to ask for http://newsite.com/
browser asks for http://newsite.com/
visitor sees web page from http://newsite.com/

Depending on the conditions, you might be able to use a Rewrite directive instead of a mod_rewrite rule.

Now before we discuss what people see at http://newsite.com/ let me know if you are with me so far.


cool openvein.org -//-

Re: Two domain names on one account?

Posted by: Erichero
Posted on: 2009-01-30 13:27:00

Hi again.

I admit that some of the stuff you mentioned was gibberish to me.

I have made some progress, but am getting stuck on the rewrite rules. I have successfully redirected the new URL to the old URL and now just need to rewrite.

Here's the scenario again:

chillisoft.co.za must stay the same
chillisoft.co.za/habanero/* must be habanerolabs.com/*

To pull this off, I redirected habanerolabs.com to chillisoft.co.za/habanero and do the rewrite after that. In my understanding that will work for both people coming in through the new URL and those with links to the old site.

My .htaccess as follows is a little bit messy and a little bit fragile, due to the main site being RubyOnRails and exceptions being added for the PHP pages. Currently everything is working fine except the rewrite is not happening:

Re: Two domain names on one account?

Posted by: Atropos7
Posted on: 2009-01-30 15:33:00

In reply to:

I admit that some of the stuff you mentioned was gibberish to me.

I have made some progress, but am getting stuck on the rewrite rules. I have successfully redirected the new URL to the old URL and now just need to rewrite.

Here's the scenario again:

chillisoft.co.za must stay the same
chillisoft.co.za/habanero/* must be habanerolabs.com/*

To pull this off, I redirected habanerolabs.com to chillisoft.co.za/habanero and do the rewrite after that. In my understanding that will work for both people coming in through the new URL and those with links to the old site.


I'm sorry, but let's clarify what you want to happen without being so simplistic.

We know you have two domains - habanerolabs.com and chillisoft.co.za

Now going back to your original post, you said

In reply to:

So the old domain would be: www.mysite.com/section/somepage
This needs to rewrite to: www.new.com/somepage


Which makes it sound as if when visting http://chillisoft.co.za/habanero/somepage you wanted the browser to change the URL in the address bar to http://habanerolabs.com/somepage and you do not want to move any files around.

Now what you have done so far is the opposite direction, where when visiting http://habanerolabs.com/somepage the browser will change the URL in the address bar to http://chillisoft.co.za/habanero/somepage

In case you don't know this already it needs to be pointed at that you can't rewrite the hostname. So if you want the hostname to change, you have to have a redirect from the old hostname to the new hostname. This means the browser will always change the URL in the address bar too.

So if you want to do what you said in your original post, you need to do a couple of things.
1. Setup habanerolabs.com as a fully-hosted domain with a web directory of /home/username/chillisoft.co.za/habanero/
2. Pleace an .htaccess file in /home/username/chillisoft.co.za/habanero
2a. It needs to redirect HTTP_HOST = chillisoft.co.za to http://habanerolabs.com/
2b. It needs to rewrite if necessary (eg, any pages on habanerolabs.com are made by RoR)

You have started off on a different track instead, so please advise which track you want to follow.

Reference: An HTTP URL is scheme://hostname/url-path

Rewriting changes the url-path internally. This is what must happen for RoR to work or to make search engine-friendly URLs for example. You can rewrite the url-path when changing the hostname too, but because the hostname changed the browser will change the URL in the address bar showing both changes.


cool openvein.org -//-

Re: Two domain names on one account?

Posted by: Erichero
Posted on: 2009-01-31 05:13:00

Thanks for the reply.

You certainly have clarified some points, although I'm still confused about rewriting, which is why I assumed I could rewrite to habanerolabs.com.

What I have done is to point the habanerolabs.com (which is on the same DH user account as chillisoft.co.za) to the chillisoft.co.za/ror/public/ directory (using DH control panel). It now brings up the main chillisoft.co.za homepage.

I tried to point it to the next level, to public/habanero, but I got a directory listing, I assume because it is missing the configuration in /public that indicates this is a Rails app.

Right now I am figuring out how to get it configured but still show the habanero directory.

Tags: htaccessexceptionslittle bitdomain namesdomain namemysite comdreamhost