Jump to content

Recommended Posts

Hi,

I have tried to do this myself but I can't make it work.

 

I have two domains, first.com and second.com, but one hosting service.

 

I want my index.php to be just the redirect to one site or the other, depending what has been typed in the url.

 

If they type www.first.com I want the code to redirect to www.first.com/index2.htm

 

If they type www.second.com I want the code to redirect to www.second.com/index3.htm

 

This also so that whatever domain they have typed will stay on the address bar. I don't want the two sites mixed up.

 

Can someone please help me?

 

I know this can be done with htaccess, but I don't have access to the root of the server.

 

I've also tried with javascript, but I couldn't get it to work either.

 

I'm more of a webdesigner, not really a raw code girl  :(

 

Thank you in advance,

Elisa

$_SERVER['HTTP_HOST']

 

to  be exact.

 

This is what I have now:

 

<?php

 

if  ($REQUEST_URL  ==  "http://www.first.com"

 

{

 

    header('location:  http://www.first.com/index2.htm');

 

 

    else  if  ($REQUEST_URL  ==  "http://www.second.com"

 

{

 

    header('location:  http://www.second.com/index3.htm');

}

?>

 

And it doesn't work. How would I change it to include your suggestion?

 

Thank you. E.

<?php
$URL = $_SERVER['HTTP_HOST'];
$NEW = preg_replace("~www.~","",$URL);
switch($NEW){
case "http://first.com":
	header("Location: http://www.first.com/index2.htm");
	exit;
break;
case "http://second.com":
	header("Location: http://www.second.com/index3.htm");
	exit;
break;
}
?>

Thank you I will try that now.

 

I've forgot to specify that right now the server is hosting first.com so any request for first.com goes directly to first.com/index.php

 

Then I've created an alias for second.com to go to first.com, so any requests for second.com will also

go to first.com/index.php

 

So the index.php is the redirect file that I'm trying to code correctly.

 

Will that code you provided still be applicable?

 

Thank you,

 

Elisa

I've tried the code little guy gave me, but still no luck. No matter which domain I try the page goes blank and it doesn't redirect.

 

What am I doing wrong?

 

Do I need to change anything on this line? Do I need to replace server with anything?

 

$URL = $_SERVER['HTTP_HOST'];

 

Just checking...

 

Thanks again.

Can anybody else help me with this?

 

You can also tell me that what I am asking for is not possible (but I doubt it).

 

Please understand that I am very new at PHP, actually I know nothing about it. So if anybody can guide me through this, I would really appreciate it.

 

Thank you,

Elisa

I've tried something else:

 

<?php
if ($_SERVER['HTTP_HOST']="www.first.com") {
header("location: http://www.first.com/index2.htm");
}  else if ($_SERVER['HTTP_HOST']="www.second.com") {
header("location: http://www.second.com/index3.htm");
}  
?>

 

Now what happens here is no matter if I type first.com or second.com it goes to www.first.com/index2.htm.

I guess it doesn't read the second part of the redirect.

Please remember that right now second.com is an alias domain name, that is directed at first.com.

So how can I make that second part work and have anything directed at second.com redirect to second.com/index3.htm? (index2.htm and index3.htm are in the same folder, because of the aliasing).

 

Thanks.

apache quistion easer and correct way ok.

 

http://httpd.apache.org/docs/1.3/mod/mod_proxy.html

 

I'm sorry, I have no idea what you are trying to tell me... and your link is a book... I would really like a simple solution, if possible. Thank you.

give this a go fingers crossed.

[code]
<?php

$url="www.first.com";

if ($_SERVER['HTTP_HOST']==$url) {

header("location: http://www.first.com/index2.htm");

}  else if (!$url) {

header("location: http://www.second.com/index3.htm");

}  
?>

 

 

or this

 

<?php

$url="www.first.com";

if ($_SERVER['HTTP_HOST']==$url) {

header("location: http://www.first.com/index2.htm");

}  

if (!$url) {

header("location: http://www.second.com/index3.htm");

}  
?>

[/code]

OMG!!! Redarrow I love you!!!

 

The first code didn't work, but the second got me thinking... I changed it slightly to this:

 

<?php

$url="www.first.com";

if ($_SERVER['HTTP_HOST']==$url) {

header("location: http://www.first.com/index2.htm");

}  else {

header("location: http://www.second.com/index3.htm");

}  
?>

 

Thank you, thank you, thank you!!!  :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.