Forum Moderators: phranque

Message Too Old, No Replies

Two domains must point to the same folder

By checking $_SERVER['HTTP_HOST']. Possible on shared hosting?

         

fargo1999

6:57 pm on Feb 8, 2009 (gmt 0)



I have two domains, let's say: domain.us and domain.de. I have a website that has two language versions (English and German). There is only one folder with contents on domain.us, the folder of domain.de is empty (but nameservers point to the same host, of course).

The websites are identical except for the language versions; depending on the language version (ie. depending on the entered domain) the proper files are loaded. So I have in setup file this condition:

------

if($_SERVER['HTTP_HOST']=='www.domain.us') {
$baseLang='eng';
$main_url='http://www.domain.us';

}

elseif($_SERVER['HTTP_HOST']=='www.domain.de') {
$baseLang='ger';
$main_url='http://www.domain.de';

}

-------

It works correctly on VPS server where (as I was told) it's possible to point two domains to the same folder. But now I'd like to move the site to a shared host..

My question is - what conditions should I enter in .htaccess so that the server recognizes the correct domain and triggers the correct script? Currently domain.us loads OK, but when I enter domain.de there is "access forbidden" page... Is it possible that this site works correctly on a shared server?

g1smd

10:35 pm on Feb 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The important thing is for the DNS for both domains to actually resolve to the same folder on the same server. If you get "Forbidden" it is likely those settings which are not in order.

fargo1999

10:57 pm on Feb 8, 2009 (gmt 0)



Hm, I'm not sure if it's possible to do that from cpanel or htaccess? I just added the second domain as an "addon-domain" in cpanel and there are now two different folders:

public_html/domainus/ ("main domain")
public_html/domainde/

Do you have an suggestion to fix that? Thanks..

fargo1999

11:11 pm on Feb 8, 2009 (gmt 0)



What I also tried to do was to put this code below in the .htaccess of public_html folder, but it still didn't work:

RewriteEngine on
rewritecond %{REQUEST_URI} domain.de/
rewriterule (.*) [domain.us...] [l,nc]

jdMorgan

11:46 pm on Feb 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to test the requested hostname (domain), then use %{HTTP_HOST}, not %{REQUEST_URI)

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.de

Jim

fargo1999

11:56 pm on Feb 8, 2009 (gmt 0)



Thanks, but now I think the problem is with the domain not resolving to the correct folder as described by g1smd (or not?).. Is there a way to make sure domain resolves to a folder, like:

domain.de should resolve to folder: public_html/domainus/

jdMorgan

12:16 am on Feb 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to do that in the server config file (httpd.conf, conf.d, etc.).

Talk to your host about this problem, since the solution depends specifically on how they have 'user accounts' configured on their servers.

I'm not sure about other configurations, but setting up multiple domains to point to one directory is no problem on my servers which have unique IP addresses. That is, these are IP-address-based shared hosting accounts, not name-based shared hosting accounts. On IP-based shared hosting, the IP address is pointed to a directory by the server config, and the server doesn't need to know the hostname(s); The hostnames are simply pointed to the server's IP address by the DNS zone file, which I control.

On name-based hosting, the server has to know the hostname(s) because it cannot use the IP address to differentiate between "user accounts." And because the hosting companies want to make money, they use the "add-on domain" concept to limit you to one or only a few extra "add-on" hostnames. The usual implementation puts these add-on domains into separate subdirectories, whether that's what you want or not.

I find the typical $1.00 per month extra fee well worth it for a unique IP address, since I can then do as I like with domains and subdomains. Typical applications are extra subdomains for testing and for separate mobile Web sites for cell phones and PDAs, and additional domains -- usually purchased simply for "brand retention" and redirected to the canonical domain, e.g. example.com and example.net, both redirected to example.org.

Jim

fargo1999

12:44 am on Feb 9, 2009 (gmt 0)



Thank you for you invaluable help, I think that explains how to tackle this problem. Host quickly replied to my question and wrote that main domain can also be pointed to a sub-directory instead of public_html and I think that may be enough, (I hope :).