domain-dependent file loading
So I just got two new domains. One for me and one for my wife. There's really no point to have two different sites becasue most of the content will be the same (and besides - I don't want to double my work). I've had it set up according to suggestions I got here on TWF a few months back, so that they access the same files on the same host server, but so that the url will remain consistant with the root domain which visitors surfed in on (unlike URL forwarding). There's only one test file but you can see each hereand here (and now everybody knows my real name )
Although I don't want to make two sites, it would be nice if our two sites could have a different header so that they look like they're different. For example, my site should say my name on top and her site should say her name on top. Is there an easy way in either html, php, or javascript (most likely php), in which you can make the webpage load a different header or graphic file, depending on the domain name currently in the browser's address bar? If so, how?
Thanks.
zollet posted this at 15:05 — 8th November 2002.
He has: 1,016 posts
Joined: May 2002
In PHP, try the below variable. If I'm not mistaking, it will return the domain name in address bar.
$_SERVER["HTTP_HOST"]
fifeclub posted this at 15:17 — 8th November 2002.
He has: 688 posts
Joined: Feb 2001
Oh, it's already set up to keep the root domain consistant in the address bar. What I need is for the page or server to recognize that URL and to load file A if it's from domain #1 and load file B if it's from domain #2. (I hope I'm explaining myself right)
(and if this proves to be a php only issue, TWF can move it to the appropriate category)
The Webmistress posted this at 15:26 — 8th November 2002.
She has: 5,586 posts
Joined: Feb 2001
You are making what you want clear, well I understand you any way, but I don't know how to do it!
zollet posted this at 16:31 — 8th November 2002.
He has: 1,016 posts
Joined: May 2002
Mike, I know and that's what I meant. Here's a sample code of what I meant...
<?php
if(preg_match(\"/wife\\.com/i\", $_SERVER[\"HTTP_HOST\"])) {
include(\"header_wife.php\");
} else {
include(\"header_husband.php\");
}
?>
fifeclub posted this at 17:58 — 8th November 2002.
He has: 688 posts
Joined: Feb 2001
awesome! thanks. That looks like it will work exactly like what I need.
:jump:
zollet posted this at 18:04 — 8th November 2002.
He has: 1,016 posts
Joined: May 2002
Hehe. Give it a try and let me know how it works.
fifeclub posted this at 05:01 — 11th November 2002.
He has: 688 posts
Joined: Feb 2001
Yup. It worked perfectly. Thanks.
BTW, let me try to sneak another question in here without creating a new thread. Dealing with the same situation of two domains on one host, is there a way to call a file in another folder (either up a few folders, or over a few folders - but not directly beneath) without using the full address?
Like if you're in www.mysite.com/folder1/ and you want to link to i a subfolder of folder 1 you can just type in the end part of the url "subfolder1/file.html". But what if the file is higher in the tree structure, or worse- on another branch? The only way I know how to get to www.mysite.com/folder2/subfolder2 is to type the whole thing in starting with http:// Is there another way in html? (like backslash or something else that says go to top first then go down this tree branch)
zollet posted this at 05:14 — 11th November 2002.
He has: 1,016 posts
Joined: May 2002
It depends. If you're using a serverside script then you can call any file on the server if you have access to it otherwise the file needs to be inside your web directory.
If you want to go back one step you can use "../". For example, if you're in mysite.com/folder1/ and you want to link to mysite.com/file.html you can simply link to "../file.html"
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.