<?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>Just a bunch of code &#187; subdomain</title>
	<atom:link href="http://www.bunchacode.com/tag/subdomain/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bunchacode.com</link>
	<description></description>
	<lastBuildDate>Sun, 11 Sep 2011 19:56:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Dynamic subdomain in cakephp</title>
		<link>http://www.bunchacode.com/programming/dynamic-subdomain-in-cakephp/</link>
		<comments>http://www.bunchacode.com/programming/dynamic-subdomain-in-cakephp/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 22:05:53 +0000</pubDate>
		<dc:creator>Funky Dude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[subdomain]]></category>

		<guid isPermaLink="false">http://www.bunchacode.com/?p=175</guid>
		<description><![CDATA[I am doing this under windows 7+Apache on my local machine. So it&#8217;s a local environment. Production setup might change slightly. In apache httpd-vhosts.conf, which can be found in Apache2.2\conf\extra\ &#60;VirtualHost *:80&#62; ServerName company.lc DocumentRoot D:/htdocs/web/public/company/app/webroot ServerAlias *.company.lc &#60;/VirtualHost&#62; And in windows hosts file which can be found windows\system32\drivers\etc\ in windows 7 127.0.0.1       test.company.lc 127.0.0.1       [...]]]></description>
			<content:encoded><![CDATA[<p>I am doing this under windows 7+Apache on my local machine. So it&#8217;s a local environment. Production setup might change slightly.</p>
<p>In apache <strong>httpd-vhosts.conf</strong>, which can be found in Apache2.2\conf\extra\</p>
<blockquote><p>&lt;VirtualHost *:80&gt;<br />
ServerName company.lc<br />
DocumentRoot D:/htdocs/web/public/company/app/webroot<br />
ServerAlias *.company.lc<br />
&lt;/VirtualHost&gt;</p></blockquote>
<p>And in windows <strong>hosts </strong>file which can be found windows\system32\drivers\etc\ in windows 7</p>
<blockquote><p>127.0.0.1       test.company.lc<br />
127.0.0.1       company.lc</p></blockquote>
<p>since windows hosts doesnt allow dynamic subdomain. You have to type out each subdomain you want accessible through your browser locally. Not a big deal.</p>
<p>Restart apache. If it doesn&#8217;t work. Flush your local dns by typing ipconfig /flushdns in cmd.exe.</p>
<p>Now you should be able to access test.company.lc correctly.</p>
<p>I have a function in my app_controller.php for grabbing the subdomain and do some comparison and checking. It&#8217;s very simple though flawed in some way.</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre>
<pre><span class="php"><span class="php-function">function</span> getSubdomain<span class="php-brackets">(</span><span class="php-brackets">)</span> <span class="php-brackets">{</span>
<span class="php-var">$domain</span> <span class="php-operator">=</span> <span class="php-function">parse_url</span><span class="php-brackets">(</span><span class="php-var">$_SERVER</span><span class="php-brackets">[</span><span class="php-string">'HTTP_HOST'</span><span class="php-brackets">]</span><span class="php-brackets">)</span>;
<span class="php-var">$domain</span> <span class="php-operator">=</span> <span class="php-function">explode</span><span class="php-brackets">(</span><span class="php-string">'.'</span>,<span class="php-var">$domain</span><span class="php-brackets">[</span><span class="php-string">'path'</span><span class="php-brackets">]</span><span class="php-brackets">)</span>;
<span class="php-keyword">if</span><span class="php-brackets">(</span><span class="php-function">count</span><span class="php-brackets">(</span><span class="php-var">$domain</span><span class="php-brackets">)</span><span class="php-operator">=</span><span class="php-operator">=</span><span class="php-number">3</span><span class="php-operator"> and </span><span class="php-operator">!</span><span class="php-keyword">empty</span><span class="php-brackets">(</span><span class="php-var">$domain</span><span class="php-brackets">[</span><span class="php-number">0</span><span class="php-brackets">]</span><span class="php-brackets">)</span><span class="php-brackets">)</span> <span class="php-brackets">{</span>
<span class="php-keyword">return</span> <span class="php-var">$domain</span><span class="php-brackets">[</span><span class="php-number">0</span><span class="php-brackets">]</span>;
<span class="php-brackets">}</span>
<span class="php-keyword">return</span> <span class="php-string">''</span>;
<span class="php-brackets">}</span></span></pre>
</div>
<p>And there you have it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bunchacode.com/programming/dynamic-subdomain-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

