<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Young Dutch Design &#187; Apache</title>
	<atom:link href="http://youngdutchdesign.com/tag/apache/feed" rel="self" type="application/rss+xml" />
	<link>http://youngdutchdesign.com</link>
	<description>Young Dutch Design is a new platform for young designers with frequently new added postings about productdesign, webdesign and other related subjects.</description>
	<lastBuildDate>Tue, 14 Jun 2011 20:25:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Dynamic subdomains using php</title>
		<link>http://youngdutchdesign.com/dyami-subdomains-using-php</link>
		<comments>http://youngdutchdesign.com/dyami-subdomains-using-php#comments</comments>
		<pubDate>Wed, 06 May 2009 11:37:25 +0000</pubDate>
		<dc:creator>Crispijn</dc:creator>
				<category><![CDATA[Webdesign]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://youngdutchdesign.com/?p=1231</guid>
		<description><![CDATA[There are several cases when you would like to use dynamic subdomains. In case your webhosting don&#8217;t support unlimited subdomains or when you&#8217;re developing a community website with a focus on the user profiles. In this case I recommend you to write a script which allows users to create personal pages with a clear address [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-1232" title="apache" src="http://youngdutchdesign.com/wp-content/uploads/2009/04/apache.png" alt="apache" width="200" height="178" />There are several cases when you would like to use dynamic subdomains. In case your webhosting don&#8217;t support unlimited subdomains or when you&#8217;re developing a community website with a focus on the user profiles. In this case I recommend you to write a script which allows users to create personal pages with a clear address like &#8216;crispijn.yourdomain.com&#8217;.</p>
<p>Obviously do I know the .htaccess solution to create subdomains. This is very handy if you don&#8217;t have cPanel or another web admin tool.</p>
<pre class="html">RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.yoursite\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.yoursite\.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/%1 [L,R]</pre>
<p>This solution points to a folder in your root so it isn&#8217;t a very dynamic one. Lets see <strong>the </strong>solution!</p>
<p><span id="more-1231"></span></p>
<h2>Apache configuration</h2>
<p>First you have to change the Apache configuration to make it by adding the following line to the httppd.conf file (the Apache configuration file).</p>
<pre class="php">ServerAlias *.yourdomain.com</pre>
<p>Read more about this configuration on the <a href="http://httpd.apache.org/docs/2.2/" target="_blank">Apache website.</a></p>
<h2>Static subdomains</h2>
<pre class="php">//array for static subdomains
$subdomains = array(
			'forum',
			'mobile',
			'demos',
			);

$match = preg_replace('#(http://)?(www\.)?(.+?)(\.yourdomain.com){1}#i','\\3', $_SERVER['HTTP_HOST']);

	if(in_array($match, $subdomains)){
		include('/root/yourdomain.com/'.$matc.'/index.php');
	}else{
		//Do normal stuff
	}</pre>
<h2>Dynamic sub domains</h2>
<p>It is also possible to create the array from a database selection. See the following example:</p>
<pre class="php">//array for static subdomains
$subdomains = array(
			'forum',
			'mobile',
			'demos',
			);

$match = preg_replace('#(http://)?(www\.)?(.+?)(\.yourdomain.com){1}#i','\\3', $_SERVER['HTTP_HOST']);

	if(in_array($match, $subdomains)){
		include('/root/yourdomain.com/'.$matc.'/index.php');
	}else{
		$sql = "SELECT nickname FROM users WHERE nickname = ".$match;
		$res = mysql_query($sql);
		$rows = mysql_num_rows($res);

		if($rows == 1){
			//pointer to user profile page
			include('/root/yourdomain.com/profiles/index.php);
		}else{
			//Do normall stuff
		}
	}</pre>
<p><strong>NOTE!</strong><br />
<em>This is a very basic way of creating subdomains. There are no build in checks or errorhandler. The way of naming your files and choosing a structure is whole yours.</em></p>
<h2>Sessions</h2>
<p>When you&#8217;re using sessions (a login system for example) the session will be lost you&#8217;re browsing to another (sub)domain. You can prevent this by adding the following line to your .htaccess file in the root of your site.</p>
<pre class="html">session.cookie_domain = "yourdomain.com"</pre>
]]></content:encoded>
			<wfw:commentRss>http://youngdutchdesign.com/dyami-subdomains-using-php/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
