Tuesday, May 12, 2009

Hosting various websites on one server with PHP

If you want to host various websites that have their own domain name on your own server then this is how you do that with PHP.

Suppose you have two domainnames blog.serveftp.com and wiki.serveftp.com. You want your server to redirect incoming calls to the proper website that you host yourself. You have set up 2 domains called: www.my_blog.com and www.my_wiki.com. On your server you have set up 2 directories in the root that contain your blog software and your wiki software.

Create an index.php file in your root that goes as follows

<?php
if ( getenv("HTTP_Host") == "www.my_blog.com" ) {
header("Location: http://your_ip/wordpress");
} elseif (getenv("HTTP_Host") == "www.my_wiki.com") {
header("Location: http://your_ip/wiki");
}
?>

depending on how you set up your blog and wiki software, you may need to include a startup file to your redirect address.

This is also possible if your connection with the internet is a dynamic IP number:

In that case take out a free account on http://www.no-ip.com e.g. http://my_name.serveblog.com and install their agent.

 

Your redirects in the above code then become http://my_name.serveblog.com/wordpress and http://my_name.serveblog.com/wiki

No comments:

Post a Comment