NetBuilders

You are welcome to look around. You will have to register before you can post a message, create a blog, chat live with our members, or add a site to our directory.



Advertise With Us

Reply Official Sulumits Retsambew Page :D
Old 23 August, 2009, 12:08 PM   #1 (permalink)
Code Otaku
 
Andy101's Avatar
 
Location: JAPAN/uk
iTrader: (0)
Blog Entries: 1
Thanked 17 Times in 14 Posts
Posts: 60
Recent Blog: Traffic Ultimatum
$NetBucks: 158
Join Date: Aug 2009
Last Online: 12 March, 2010 13:38 PM
Send a message via Skype™ to Andy101
Default Multiple Sub-domain Site Script

Hi folks, my first post here

I am developing a PHP script that customizes a web page template according to the sub-domain that was used to access the site. Each sub-domain will be owned by a member of the main host site so their details are used to customize the page.

So my plan is to use .htaccess on LAMP (Linux, Apache etc.) hosting to rewrite the URLs from:

anysubdomain.mysite.com to www.mysite.com/index.php?sub=anysubdomain
Then index.php will produce the custom page.

My understanding is that the DNS Zone File for the website needs to have an entry to handle wildcard subdomains.

So I can use WHM (Web Host Manager) to add an entry like:

*.mysite.com. IN A 90.168.0.1

where the IP and domain name is as per my site.

Or I ask my Tech support at my host to do this for me.

So if this works, any sub-domain at my site should display the home page.

Now, to pass the sub-domain value to the index.php script, I will use .htaccess

I think the code I need is something like:
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^[-a-z0-9]{2,}\..+$ [NC]
RewriteRule ^/(.*)$ /index.php/?sub=%1 [R=301,L]
This then, allows the sub-domain value to be accessed by the PHP script.

Well I will be trying to get this working on Monday but thought it would be good to post it up here.

Note that I have not tested this out yet, it's just what I think may work.

Update:
It turned out to be quite simple:

In cPanel simply add a new subdomain using the wildcard character *

And here is a test script to use in index.php that displays the name of the subdomain:
Code:
<?php
$host = getenv('HTTP_HOST');
$pattern = '/([-a-zA-Z0-9]{2,})\.[^c]/';
preg_match($pattern, $host, $matches);
$subdomain = $matches['1'];

echo"Subdomain: $subdomain";
?>

Last edited by Andy101; 24 August, 2009 at 03:35 AM..
  Reply With Quote
Thanked by:
A12Alex (28 August, 2009), Will.Spencer (27 August, 2009)
Reply

Bookmarks

Tags
multiple, script, site, subdomain, wildcard subdomains


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[WTS] Auto updating site with multiple earning streams - www.PizzaGang.com the dopant Sites 1 14 September, 2009 13:50 PM
Domain Name Checking Script hendricius Building 6 24 August, 2009 09:22 AM
[Free] Image Hosting Script + Multiple Upload + Auto-Watermarker Mr.Bill Scripts 9 15 May, 2009 19:59 PM
Multiple Site hosting in the UK YogiBeer Managing 14 8 March, 2009 09:12 AM
Looking for WHOIS Domain Status script TopDogger Programming 4 26 February, 2009 18:38 PM


All times are GMT. The time now is 13:55 PM.
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.1
vBAdvertise v1.0.0 Copyright ©2009, PixelFX Studios
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios