Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php scripting subdomains

Status
Not open for further replies.

durda

Programmer
Jan 3, 2003
25
US
I was wondering if anyone knew if it was possible to script the following in PHP. Wilcarded DNS is not possible.

for every directory existing in httpdocs it acts like a subdomain.

so I have a directory called specialed and when a person types it takes the visitor to the index.html in the specialed directory.
 
with php, yes it is possible. but not with php alone. you would need to configure apache to recognise all these domains and direct them to the relevant script. alternatively have all requests listening to port 80 directed to your despatch script.

the php is easy. make this file the index.php in the directory that is your default webroot

Code:
<?php
include redirect();
function redirect(){
	$r = explode(".",$_SERVER['SERVER_NAME']);
	$path = array();
	if (strtolower($r[0]) !== '[URL unfurl="true"]www')[/URL] {
		return $r[1].'/index.html';
	} else {
		return $r[0].'/index.html';
	}
}
?>

that's it!

but personally i would think it were much better to use the mod_rewrite module within apache.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top