2 Domains, 1 Site, load different index files
Moderator: General Moderators
2 Domains, 1 Site, load different index files
Hello Everyone, this is my first post on this great and very useful site.
I'm hoping someone can give me a quick and simple answer for this one.....
Here's my scenario:
I have 2 domain names that point to one website. One domain is english the other french. I want an index.php file to handle what index file is loaded.
If the user types in french.com I want it to load the index_french.html file, if the user types english.com I want the site to load index.html
Sounds simple enough, but I may be wrong?
Thanks in advance for your help.
I'm hoping someone can give me a quick and simple answer for this one.....
Here's my scenario:
I have 2 domain names that point to one website. One domain is english the other french. I want an index.php file to handle what index file is loaded.
If the user types in french.com I want it to load the index_french.html file, if the user types english.com I want the site to load index.html
Sounds simple enough, but I may be wrong?
Thanks in advance for your help.
Re: 2 Domains, 1 Site, load different index files
a very basic way of doing it:
put that at the top if index.PHP
make index.php your English version.
if they used the French domain name then they will be redirected to index_french.html. if not then it will continue loading index.php
Code: Select all
if($_SERVER['SERVER_NAME'] == 'french.mysite.com'){
header('Location: http://french.mysite.com/index_french.html');
}
make index.php your English version.
if they used the French domain name then they will be redirected to index_french.html. if not then it will continue loading index.php
Re: 2 Domains, 1 Site, load different index files
Thank you for your quick response.....
I should have pointed out that my site does not utilize PHP at all the site is all static HTML pages. Really I just wanted to implement a PHP file to handle the different domain names, so I would assume an index.php file created with this rule for each domain should do the trick?
I'm going to test this now and report back.
Thanks again....
I should have pointed out that my site does not utilize PHP at all the site is all static HTML pages. Really I just wanted to implement a PHP file to handle the different domain names, so I would assume an index.php file created with this rule for each domain should do the trick?
I'm going to test this now and report back.
Thanks again....
Re: 2 Domains, 1 Site, load different index files
yeah... for the most part
you could do this:
you could do this:
Code: Select all
if($_SERVER['SERVER_NAME'] == 'french.mysite.com'){
header('Location: http://french.mysite.com/index_french.html');
}else if($_SERVER['SERVER_NAME'] == 'english.mysite.com'){
header('Location: http://english.mysite.com/index.html');
}else{
echo "Please choose a language. <a href='/index.html'>English</a> or <a href='/index_french.html'>French</a>";
}
Re: 2 Domains, 1 Site, load different index files
or you could skip PHP all together and use javascript
Code: Select all
<script>
if(window.location.hostname == 'french.mysite.com'){
window.location = 'http://french.mysite.com/index_french.html';
}
</script>
Re: 2 Domains, 1 Site, load different index files
This worked great, thanks again for your help!
-
internet-solution
- Forum Contributor
- Posts: 220
- Joined: Thu May 27, 2010 6:27 am
- Location: UK
Re: 2 Domains, 1 Site, load different index files
Whats happens if the user blocks javascript????buckit wrote:or you could skip PHP all together and use javascriptCode: Select all
<script> if(window.location.hostname == 'french.mysite.com'){ window.location = 'http://french.mysite.com/index_french.html'; } </script>
Re: 2 Domains, 1 Site, load different index files
I used the PHP option, and everything worked out great......thanks again. I didn't expect an answer so quickly.......
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: 2 Domains, 1 Site, load different index files
If your site doesn't require PHP and is composed of static pages, perhaps this could be accomplished also with .htaccess rules.
Re: 2 Domains, 1 Site, load different index files
http://corz.org/serv/tricks/htaccess2.php
multiple domains in one root
If you are in the unfortunate position of having your sites living on a host that doesn't support multiple domains, you may be forced to roll your own with .htaccess and mod_rewrite. So long as your physical directory structure is well thought-out, this is fairly simple to achieve.
For example, let's say we have two domains, pointing at a single hosted root; domain-one.com and domain-two.com. In our web server root, we simply create a folder for each domain, perhaps one/, and two/ then in our main (root) .htaccess, rewrite all incoming requests, like this..
All requests NOT already rewritten into these folders, transparently rewrite..
#two domains served from one root..
RewriteCond %{HTTP_HOST} domain-one.com
RewriteCond %{REQUEST_URI} !^/one
RewriteRule ^(.*)$ one/$1 [L]
RewriteCond %{HTTP_HOST} domain-two.com
RewriteCond %{REQUEST_URI} !^two
RewriteRule ^(.*)$ two/$1 [L]
All requests for the host domain-one.com are rewritten (not R=redirected) to the one/ directory, so long as they haven't already been rewritten there (the second RewriteCond). Same story for domain-two.com. Note the inconsistency in the RewriteCond statement; !^/dir-name and !^dir-name should both work fine.
Also note, with such a simple domain & folder naming scheme, you could easily merge these two rule sets together. This would be unlikely in the real world though, which is why I left them separate; but still, worth noting.
Other general settings and php directives can also go in this root .htaccess file, though if you have any further rewrite you'd like to perform; short URL's, htm to php conversion and what-not; it's probably easier and clearer to do those inside the sub-directory's .htaccess files.
There are 10 types of people in this world, those who understand binary and those who don't