...

View Full Version : Sub-domain redirecting



CurtWRC
02-09-2006, 02:08 PM
Hello,

I have an account at brinkster.com for my website, http://www.rallystuff.net. As I have a separate website within a folder on my site (http://www.rallystuff.net/lomax/index.aspx) I want use a subdomain called http://mosasaur.rallystuff.net to access this site. However when brinkster created me this subdomain it takes you to the homepage of my main site. They have told me that to redirect this link to /lomax I have to use the code below. However because my knowledge of PHP is very limited as I code in ASP.NET, and I haven't got contact with the guy who originally designed my site I don't know how to edit this code to make it work.

Any help would be most appreciated,
Thanks,
Curt.


<?
$SiteNameURL = $_SERVER['HTTP_HOST'];

switch ($SiteNameURL) {

case "domain.com":
include 'page1.php';
break;

case "www.domain.com":
include 'page1.php';
break;

case "yourotherdomain.com":
include 'page2.php';
break;

case "www.yourotherdomain.com":
include 'page2.php';
break;

case "subdomain1.domain.com":
include 'page3.php';
break;

case "subdomain2.domain.com":
include 'page4.php';
break;

default:
include 'other.php';

}
?>

degsy
02-09-2006, 03:48 PM
That code is including file. If you want to redirect use header("Location...
http://uk.php.net/header




case "subdomain1.domain.com":
header("Location: http://www.rallystuff.net/lomax/index.aspx");
break;

CurtWRC
02-09-2006, 05:29 PM
Thanks for your help. I tried this but it still wouldn't work. This is the code I used:


<?
$SiteNameURL = $_SERVER['HTTP_HOST'];

switch ($SiteNameURL) {

case "mosasaur.rallystuff.net":
header("Location: http://www.rallystuff.net/lomax/index.aspx");
break;

}
?>

I get this error:

"Warning: Cannot modify header information - headers already sent by (output started at c:\Sites\Single18\curttimson\webroot\index.php:9) in c:\Sites\Single18\curttimson\webroot\index.php on line 15"


Any ideas whats wrong?
Thanks,
Curt.

CurtWRC
02-09-2006, 07:14 PM
Could it be anything to do with where it is put in the code. If so this is the code above the HTML tag:


<?php

include("connect.inc");

include('news.inc');

?>

<?
$SiteNameURL = $_SERVER['HTTP_HOST'];

switch ($SiteNameURL) {

case "mosasaur.rallystuff.net":
header("Location: http://www.rallystuff.net/lomax/index.aspx");
break;

}
?>

CurtWRC
02-09-2006, 07:17 PM
Ive worked out where I went wrong. It has to be in the <?php tag:


<?php

include("connect.inc");

include('news.inc');



$SiteNameURL = $_SERVER['HTTP_HOST'];

switch ($SiteNameURL) {

case "mosasaur.rallystuff.net":
header("Location: http://www.rallystuff.net/lomax/index.aspx");
break;

}

?>


Thanks for your help.

coyotte508
02-09-2006, 07:39 PM
put the "header" before any echo in the php script and before the very first html part( before <html>)

CurtWRC
02-09-2006, 07:54 PM
put the "header" before any echo in the php script and before the very first html part( before <html>)
The way I have it above works fine thanks. However when mosasaur.rallystuff.net redirects to /lomax the URL appears as /lomax. Is there a way of having it appear as mosasaur.rallystuff.net instead?

degsy
02-10-2006, 03:50 PM
That's the way you have it setup.

If you want it to be on the URL then you will have to create it into a proper sub domain rather than a redirect. You do this at server level.

The other option is to use a frame redirect. Not pretty.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum