View Full Version : .htaccess : two domains, one website, keep both domain
ChristianLebe
18-04-2011, 09:20 AM
Hello all,
I have been puzzled by this client request. Basically they have a .com.au site and now they are opening a branch in singapore. And so we bought them a .com.sg domain.
Both domains currently pointing to the same website (joomla CMS). It is quite an easy setup, .com.sg is an addon domain, setting redirection to .com.au solves the problem.
Now the issue is, they want the .com.sg still appears on the web browser when a user goes to the .com.sg website. But obviously we dont want to maintain two websites.
So I have got two solutions that I'm aware of:
1. Create an iframe that fills the whole screen. So when someone types .com.sg they will see an invisible frame that points to .com.au
Cons: The .com.sg will stay static - it will stay the same all across the page.
2. We can use .htaccess to camuflage the .com.sg to points to the .com.au directory, so essentially it looks like a real .com.sg site.
Cons: I dont know how to do it. Google doesnt really help me much.:confused::confused:
Does anyone know how to do option 2? Or is there any better option?
Many thanks.
Christian
You want foo.com.sg to be a "ServerAlias". You'll probably want to get your hands on the apache configuration, not just an .htaccess file.
Don't try option #1, not worth the hassle :)
Franki
18-04-2011, 11:57 AM
Joomla, like most other CMS will only accept one domain in it's config file, therefore, it's not possible (not impossible), to serve to different domains from one install while maintaining 2 different domains as the URL.
You could setup a sniffer that rewrites Joomla's config file with the domain that user accesses. Or modify Joomla so that it ignores the "domain name" variable (and use what ever the user accesses).
Remove it as a redirected addon domain and change it to a parked domain.
Yaheed
18-04-2011, 01:31 PM
Joomla, like most other CMS will only accept one domain in it's config file, therefore, it's not possible (not impossible), to serve to different domains from one install while maintaining 2 different domains as the URL.
Lies! :P It reads the domain name from variables I believe so the domain can be anything as long as you have used absolute or relative links to images/files/locations. i.e. /path/to/file rather than http://domain.com/path/to/file.
There is a "live site" option in the configuration.php file but you don't have to fill it out, completely optional.
But yeah as Vee has said, keep it as parked. Can't you just have both domains pointing to the same IP address with the A records? That's another solution.
Can't you just have both domains pointing to the same IP address with the A records? That's another solution.
I took his use of "addon domain" to be an indication of the hosting service being managed by cPanel.
Yaheed
18-04-2011, 03:12 PM
I took his use of "addon domain" to be an indication of the hosting service being managed by cPanel.
Ahk, yeah well whatever works I guess. ;-)
ChristianLebe
19-04-2011, 01:21 PM
dang! it works like a charm.. a very simple solution..!!!!
Thanks Vee!!
Ps. are you Vee who worked at moodle before?
Ps. are you Vee who worked at moodle before?
Unless you have a substantial cheque for me, nope.
Franki
20-04-2011, 05:49 PM
Lies! :P It reads the domain name from variables I believe so the domain can be anything as long as you have used absolute or relative links to images/files/locations. i.e. /path/to/file rather than http://domain.com/path/to/file.
There is a "live site" option in the configuration.php file but you don't have to fill it out, completely optional.
But yeah as Vee has said, keep it as parked. Can't you just have both domains pointing to the same IP address with the A records? That's another solution.
lol! Yeah, Parking will fix all path (relative) issues. But for certain things, it may use the absolute path, which means the domain name from the variable/config file will be used to populate. Look at the outputted html, especially around the CSS/scripts declarations, most likely, the paths here will be Absolute and that of the original domain (as entered in the CMS' config)...
thsutton
19-05-2011, 11:35 PM
It sounds like this problem is solved but for future reference using a .htaccess to respond to requests depending on the hostname is relatively easy with mod_rewrite.
If your original .htaccess contains something like this (from Drupal) to respond to every request (that isn't a real file or folder) with index.php:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
you could modify it to serve singaporesite.php when the user visits example.com.sg and index.php when they use another hostname:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} example.com.sg$
RewriteRule ^ singaporesite.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
How you make that work on Joomla side, I have no idea.
vBulletin® v3.8.4, Copyright ©2000-2013, Jelsoft Enterprises Ltd.