| | |
Can php allow me to create whatever.homepage.com address
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
In order to do this, your webhost will have to enter a DNS record for the subdomain so that their routers know to point it to your server. Then, you can use either a .htaccess or .cgi file (most likely PHP as well) to redirect the subdomain to a folder of your choice.
•
•
Join Date: Dec 2004
Posts: 2
Reputation:
Solved Threads: 0
Well my webhosting company have told me of the DNS subdomain record however that will only point to another domain ie daniweb.homepage.com would point to daniweb.com. What I am trying to do is point daniweb.homepage.com to homepage.com/daniweb/. some one said it could be done via php and I came her to find out before I went off to learn a new script that I might not use.
So what you are telling me is that php cannot help me? yes - no?
So what you are telling me is that php cannot help me? yes - no?
Yes you can do this.
You can simply redirect users to the correct folder.
There are two ways to do this really. the first is static. i.e. you set up instances of each domain you intend using. The second is dynamic, the script redirects users blindly, depending on whatever they put in as a subdomain. For dynamic redirection wildcards is required on your DNS. If you are using a free dynamic dns for this site, i suggest you check your settings and enable wildcards if applicable.
I must mention that this only works with HTTP1.1 compliant browsers, Some HTTP1.0 do not post the details required to make this work ($HTTP_POST).
Your index.php:
[PHP]
$subdomain = explode(".",$HTTP_HOST);
$default = ("main.php");
/* Static
if($subdomain[0] == "folder1"){
header("Location:http://$HTTP_HOST/folder1/");
}elseif($subdomain[0] == "folder2"){
header("Location:http://$HTTP_HOST/folder2/");
// and so on...
}else{
header("Location:http://$HTTP_HOST/$default");
}
*/
// Dynamic
if(is_dir("$DOCUMENT_ROOT/$subdomain[0]")){
header("Location:http://$HTTP_HOST/$subdomain[0]");
}else{
header("Location:http//$HTTP_HOST/$default");
}
[/PHP]
In the case of dynamic redirection, the script checks to see if the folder exists before forwarding the user to the folder. If it does not, the user is redirected to the default. In this case, domain.com/main.php .
Hope this helps
You can simply redirect users to the correct folder.
There are two ways to do this really. the first is static. i.e. you set up instances of each domain you intend using. The second is dynamic, the script redirects users blindly, depending on whatever they put in as a subdomain. For dynamic redirection wildcards is required on your DNS. If you are using a free dynamic dns for this site, i suggest you check your settings and enable wildcards if applicable.
I must mention that this only works with HTTP1.1 compliant browsers, Some HTTP1.0 do not post the details required to make this work ($HTTP_POST).
Your index.php:
[PHP]
$subdomain = explode(".",$HTTP_HOST);
$default = ("main.php");
/* Static
if($subdomain[0] == "folder1"){
header("Location:http://$HTTP_HOST/folder1/");
}elseif($subdomain[0] == "folder2"){
header("Location:http://$HTTP_HOST/folder2/");
// and so on...
}else{
header("Location:http://$HTTP_HOST/$default");
}
*/
// Dynamic
if(is_dir("$DOCUMENT_ROOT/$subdomain[0]")){
header("Location:http://$HTTP_HOST/$subdomain[0]");
}else{
header("Location:http//$HTTP_HOST/$default");
}
[/PHP]
In the case of dynamic redirection, the script checks to see if the folder exists before forwarding the user to the folder. If it does not, the user is redirected to the default. In this case, domain.com/main.php .
Hope this helps
I'm pink, therefore, im spam.
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
•
•
Join Date: Jan 2005
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by ReDuX
Yes you can do this.
You can simply redirect users to the correct folder.
There are two ways to do this really. the first is static. i.e. you set up instances of each domain you intend using. The second is dynamic, the script redirects users blindly, depending on whatever they put in as a subdomain. For dynamic redirection wildcards is required on your DNS. If you are using a free dynamic dns for this site, i suggest you check your settings and enable wildcards if applicable.
I must mention that this only works with HTTP1.1 compliant browsers, Some HTTP1.0 do not post the details required to make this work ($HTTP_POST).
Your index.php:
[PHP]
$subdomain = explode(".",$HTTP_HOST);
$default = ("main.php");
/* Static
if($subdomain[0] == "folder1"){
header("Location:http://$HTTP_HOST/folder1/");
}elseif($subdomain[0] == "folder2"){
header("Location:http://$HTTP_HOST/folder2/");
// and so on...
}else{
header("Location:http://$HTTP_HOST/$default");
}
*/
// Dynamic
if(is_dir("$DOCUMENT_ROOT/$subdomain[0]")){
header("Location:http://$HTTP_HOST/$subdomain[0]");
}else{
header("Location:http//$HTTP_HOST/$default");
}
[/PHP]
In the case of dynamic redirection, the script checks to see if the folder exists before forwarding the user to the folder. If it does not, the user is redirected to the default. In this case, domain.com/main.php .
Hope this helps
I'm just starting out with php and this is exactly what i want to do
however i'm not sure how to impliment the example you give
i.e. does this example run as a script on the default webpage for the domain
(would i put this in domain.com/index.html)
or does the example need to be a .php file that is actioned by a page?
as I said I probably sound like a 1 year old trying to say "dadda" but please help if you can withstand my ignorance

obviously the static way would be best for my to try out
(although i think i can use wildcard for dns, so once i get a clue i might try the dynamic way)
That example would be the default 'index.php' page for your domain i.e.
http://www.domain.com/index.php
It will then be run, and depending on the subdomain you requested, it will direct to the page 'main.php' in the subfolder requested.
e.g. requesting the site/page http://pancake.domain.com will direct the users browser to http://www.domain.com/pancake/main.php
Hope that mekes it a little more clear
http://www.domain.com/index.php
It will then be run, and depending on the subdomain you requested, it will direct to the page 'main.php' in the subfolder requested.
e.g. requesting the site/page http://pancake.domain.com will direct the users browser to http://www.domain.com/pancake/main.php
Hope that mekes it a little more clear
I'm pink, therefore, im spam.
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
http://www.vivaci.net - Quality Webhosting
http://gaming.vivaci.net - FAST UK Gaming servers
http://www.getsigned.org - Free Image Uploads
![]() |
Similar Threads
- Create a homepage (C++)
- how to create an email address (PHP)
- How to create a static Ip address (Domains and DNS)
Other Threads in the PHP Forum
- Previous Thread: Domain Manager Problem
- Next Thread: How do I add this to that to get this?
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion regex remote screen script search server sessions smarty sms soap sorting source space sql startup stored syntax system table traffic tutorial update upload url validator variable video web xml youtube zend






