Jump to content

if url = ... then redirect to this page?


dzhax

Recommended Posts

hello. i use no-ip.org for my domain name. i was wondering if there is a php script to do something likeif url in address bar is mail.mydomain.com then redirect to mail.htmlif url in address bar is forum.mydomain.com then redirect to forum.htmletc...thanks in advance for any help on this topic. i am new to php so any help would be great.

Link to comment
Share on other sites

thank you for the reply. as i said before i am new to php. where would i put this switch statement? it would need called when the page loads.

Link to comment
Share on other sites

It must be at the top of your PHP, before anything, including whitespace, is output. That's because you'll need to use the header function, which sets an HTTP header to be sent. HTTP headers must be the first things sent to the browser.

Link to comment
Share on other sites

i just read the page about the header function. made no sense of it. could you please post an example of a full working .php with this in it. it can be plain. like no text or anything. it just checks the url and then i can add the redirect in after. so maybe ill understand?

Link to comment
Share on other sites

i just read the page about the header function. made no sense of it. could you please post an example of a full working .php with this in it. it can be plain. like no text or anything. it just checks the url and then i can add the redirect in after. so maybe ill understand?
You won't understand what it is until reading the standard, which is about as bad as a legal document. (I use exit instead of break here because there's no need to keep thinking when the user won't be using the rest of the page.)
<?phpswitch($_SERVER['SERVER_NAME']){	case 'mail.example.com':		header('Location:/mail'); // redirects to mail.example.com/mail		exit;	case 'forum.example.com':		header('Location:/forum'); // redirects to forum.example.com/forum		exit;	default:		// The user somehow found a subdomain you didn't know you had.  :\}?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...