YNOT
  • Home
  • Industry News
    • Adult Business News
    • Adult Novelty News
    • YNOT Magazine
    • EU News
    • Opinions
    • Picture Galleries
  • PR Wire
    • Adult Company News
    • Adult Retail News
    • Adult Talent News
    • Adult Videos News
  • Podcasts
  • Industry Guides
    • Adult Affiliate Guide
    • Affiliate Marketing for Beginners
    • Top Adult Traffic Networks
    • Top Adult PR Agents
    • Funding an Adult Business
  • Business Directory
    • View Categories
    • View Listings
    • Submit Listing
  • Newsletters
  • Industry Events
    • Events Calendar
    • YNOT Cam Awards | Hollywood
    • YNOT Awards | Prague
    • YNOT Cammunity
    • YNOT Summit
    • YNOT Reunion
  • Login with YNOT ID
YNOT University: Educational articles and tutorials

Coders Corner / Psuedo Sub-Domains With PHP

Posted On 04 Nov 2000
By : admin

What do YOU think about this Script? Add YOUR comments at the end!

Here’s a handy bit of PHP code you can use to simulate Third Level Domains with minimal involvement from your ISP or webmaster.What do YOU think about this Script? Add YOUR comments at the end!

Here’s a handy bit of PHP code you can use to simulate Third Level Domains with minimal involvement from your ISP or webmaster. For those of you unfamiliar with them, Third Level Domains are those whose names replace the commonly used “www.” For example, my main Traffic Filter is at http://www.adultsitelisting.com but I commonly refer to it as http://AdultSiteListing.com without the “www.” It’s the “www.” That I want to replace, rather than eliminate – more for marketing and aesthetics than for “function.”

As I’m about to start working on a new project site, “Asian Adult Site Listing” I asked “Buran” (our intrepid CTO) to setup http://asian.adultsitelisting.com for me – as well as a few other sub-domains while he was at it. He offered me a better solution however, one that was more flexible for the uses I had in mind, and one that would allow me to add, subtract, rename, or redirect these psuedo sub-domains at will.

He renamed my “home page” to “default.html” (it could be any name you wish) and setup a new home page at index.php with the code given below as the only content. Now, all I had to do was add the desired sub-directories (folders) to my site, for example:

http://www.adultsitelisting.com/asian
http://www.adultsitelisting.com/amateur
http://www.adultsitelisting.com/hardcore

Because the DNS settings were not changed (other than the addition of the *.domain wild card and “ServerAlias *.sitename.com” in the Apache config – have your webmaster or ISP do this for you), any browser request for asian.adultsitelisting.com would go to the new index page where the PHP code would look down the path for a folder called “asian” (http://www.adultsitelisting.com/asian) and redirect the surfer to that directory (just as if it was a “true” Third Level Domain). If that directory is not found, the surfer would be directed to the default page, “default.html.” Cool, huh? Try it on your site!

$defaultpage = “default.html”;
$sitename = “adultsitelisting.com”;

if(eregi(“^” . $sitename . “$”, $HTTP_HOST)) {
include($defaultpage);
} else {
$subdomain = explode(“.”, $HTTP_HOST);
$subdomain = strtolower($subdomain[0]);
if($subdomain == “www”) {
include($defaultpage);
} else {
if(file_exists($DOCUMENT_ROOT . “/” . $subdomain)) {
Header(“Location: http://www.$sitename/$subdomain”);
} else {
include($defaultpage);
}
}
}

Now, it’s very important for you to add the standard PHP “containers” to this script. It must start with < ? and end with ? > (I only omitted them from the script here because they kept it from being displayed in the text box).

[ MORE SCRIPTS | CODER’S CORNER >>

Reader Comments on this Article:

Comment by:Summary:
Stephena handy script indeed
michael
All I get is a 403 error

  • google-share
Previous Story

Newbies Helping Newbies

Next Story

Introduction to Linux

Leave a Reply Cancel reply

You must be logged in to post a comment.

Sponsor

YNOT Shoot Me

YNOTShootMe.com has exclusive pics from adult industry business events. Check it out!

YNOT Directory

  • The European Summit
    Industry Trade Show & Events
  • Naughty America
    Paysite Affiliate Programs
  • Coinsnap
    Online Billing Services
  • Premiere Listing

    ComeShootMe

    More Details

RECENT

POPULAR

COMMENTS

Kasey Kei Sinks Her Teeth Into Spooky New Gender X Films Scene

Posted On 05 Sep 2025

ASN Awards Announces 2025 Winners

Posted On 05 Sep 2025
Elegant Angel Releases “Shared: A Hotwife Origin Story”

Elegant Angel Releases “Shared: A Hotwife Origin Story”

Posted On 05 Sep 2025

Vanessa, Meet Vivid

Posted On 29 Sep 2014
Laila Mickelwaite and Exodus Cry

Laila Mickelwaite, Exodus Cry and their Crusade Against Porn

Posted On 03 May 2021

Someone puts Gal Gadot in one of your vids? Take it down!

Posted On 13 Dec 2017

Hoping viewers can also enjoy a spooky...

Posted On 24 Oct 2023

now a days these type of games will get...

Posted On 17 Jul 2023

good move from adent. these type of...

Posted On 06 Jul 2023

Sponsor

Sitemap
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkPrivacy Policy