<?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>The WEB CELT &#187; PHP &amp; MySQL</title>
	<atom:link href="http://www.webcelt.com/news/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webcelt.com/news</link>
	<description>  "Imagination is more important than knowledge."</description>
	<lastBuildDate>Tue, 20 Dec 2011 03:17:11 +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>PHP Domain Redirect</title>
		<link>http://www.webcelt.com/news/2007/06/17/php-domain-redirect/</link>
		<comments>http://www.webcelt.com/news/2007/06/17/php-domain-redirect/#comments</comments>
		<pubDate>Mon, 18 Jun 2007 00:59:22 +0000</pubDate>
		<dc:creator>WebCelt</dc:creator>
				<category><![CDATA[PHP & MySQL]]></category>

		<guid isPermaLink="false">http://www.webcelt.com/news/archives/6</guid>
		<description><![CDATA[Our PHP Domain Redirect script is the perfect choice when you are parking domains at one central location and you need to split the web traffic to different addresses based upon the URL name.  For example, say your primary location is firstdomain.com, but you also own a second domain name that is parked at this location [...]]]></description>
			<content:encoded><![CDATA[<p>Our PHP Domain Redirect script is the perfect choice when you are parking domains at one central location and you need to split the web traffic to different addresses based upon the URL name. </p>
<p>For example, say your primary location is <em>firstdomain.com</em>, but you also own a second domain name that is parked at this location (<em>seconddomain.com</em>). The key is to create different directories to store each website and then funnel the traffic based upon the domain name.</p>
<p>To accomplish this in PHP we employ a special PHP server variable called <em><strong>$_SERVER["HTTP_HOST"]</strong></em>. This variable contains the name of the URL as entered in the address bar of the web browser. You can find a list of all of the special PHP <a href="http://us2.php.net/reserved.variables">server variables</a> on <a href="http://www.php.net" title="Your Source for PHP documentation">PHP.net</a>. Some of the variables available are the <em><strong>document_root</strong></em> (contains the root location), <em><strong>http_referer</strong></em> (from what URL the vistor arrived at your site), <em><strong>http_user_agent</strong></em> (shows the browser and version of the vistor).</p>
<pre>
&lt;?php 

$domain = $_SERVER["HTTP_HOST"];
if (($domain == "celtichearts.com") ||
   ($domain == "www.celtichearts.com")) { 

   header("location: http://www.celtichearts.com/mail"); 

} 

if (($domain == "webcelt.com") ||
   ($domain == "www.webcelt.com")) { 

   header("location: http://www.webcelt.com/news"); 

}
?&gt;</pre>
<p>Our script&#8217;s first job is to grab the URL from the address bar by using the server side variable <em><strong>$_SERVER["HTTP_HOST"]</strong></em>. We simply place that in the variable<strong> <em>$domain</em></strong> and then test for each website &#8211; redirecting based on the name of the web address.</p>
<p>In this example, we show how <strong><em>The WEB CELT</em></strong> website uses PHP Domain Redirecting to host 2 different websites at one location. Because our hosting provider only allows 1 primary domain (<em><a href="http://www.celtichearts.com/">www.celtichearts.com</a></em>), we park the domain (<a href="http://www.webcelt.com/"><em>www.webcelt.com</em></a><em>) </em>and then redirect both to the appropriate location.</p>
<p>Redirecting is accomplished by using PHP&#8217;s <em><a href="http://us2.php.net/header" title="PHP Header Command Details">header()</a></em> command. Remember that <em>header()</em> must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP &#8211; otherwise this will result in a nasty error.</p>
<p>And that is our quick and dirty PHP Domain Redirect Script. This is the perfect solution when you need a means to direct your vistors to different parts of your website based upon the URL the vistor entered. It is also a great way to accomplish redirects without learning or using <em>.htaccess</em>. Although I am sure we will be talking about <em>.htaccess</em> commands in future posts to <em><strong>The WEB CELT</strong></em>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webcelt.com/news/2007/06/17/php-domain-redirect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

