<?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>Stijn D&#039;haese &#187; Apache</title>
	<atom:link href="http://blog.stijn-dhaese.be/category/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stijn-dhaese.be</link>
	<description>This is the personal blog of Stijn D&#039;haese. A little freedom on the net by an analyst, developer and system administrator from Belgium.</description>
	<lastBuildDate>Fri, 23 Dec 2011 18:44:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to invisible redirect websites in Apache. [updated]</title>
		<link>http://blog.stijn-dhaese.be/2007/10/how-to-invisible-redirect-websites-in-apache-updated/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-invisible-redirect-websites-in-apache-updated</link>
		<comments>http://blog.stijn-dhaese.be/2007/10/how-to-invisible-redirect-websites-in-apache-updated/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 14:24:54 +0000</pubDate>
		<dc:creator>Stijn</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.stijn-dhaese.be/blog/?p=3</guid>
		<description><![CDATA[Problem: You have 1 hosting package but 2 websites. How do you make a nice looking redirect, so that they run nicely side by side, with .htaccess? There are 2 common hosting situations that I will explain, the first is VirtualDocumentroot what gives you access to sub domains (example: http://image.domain.com). The other one is Documentroot [...]]]></description>
			<content:encoded><![CDATA[<p><center><a href="http://www.pcextreme.nl/?tt=1652_44885_27592_" target="_blank"><img src="http://ti.tradetracker.net/?c=1652&amp;m=44885&amp;a=27592&amp;t=html" border="0" alt="" width="468" height="60" /></a></center></p>
<p class="intro"><strong>Problem</strong>: <em>You have 1 hosting package but 2 websites. How do you make a nice looking redirect, so that they run nicely side by side, with .htaccess?</em></p>
<p><span id="more-3"></span></p>
<p>There are 2 common hosting situations that I will explain, the first is VirtualDocumentroot what gives you access to sub domains (example: http://image.domain.com). The other one is Documentroot what will lead all the traffic to the www folder (http://www.domain.com is the same as http://domain.com).</p>
<p>Here you can see a <a href="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/virtualdocumentroot.jpg">demo</a> of virtual root (sort of).</p>
<h3>VIRTUALDOCUMENTROOT.</h3>
<p><a href="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/simple_example.jpg" rel="lightbox[3]" title="VirtualDocumentRoot"><img src="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/simple_example.jpg" alt="" title="VirtualDocumentRoot" width="106" height="87" class="alignright size-full wp-image-5" /></a>When you use VirtualDocumentroot, you have a root folder where you can place sub folders who represent sub domains. In the figure &#8220;VirtualDocumentroot&#8221; you can see an example of a basic hosting package using VirtualDocumentroot. There is an www-folder who represents http://www.domain.com and you have an image folder who represents http://image.domain.com.</p>
<p>The first thing we are going to do, is to create a .htaccess file that will move all the traffic without a sub domain to the www-folder (http://domain.com becomes http://www.domain.com). Copy and modify the following code in a standard text-editor like notepad or gedit:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="" style="font-family:monospace;">RewriteEngine On
&nbsp;
RewriteCond %<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span> ^WebsiteNameA.com$ <span class="br0">&#91;</span>NC<span class="br0">&#93;</span>
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span>$ http://www.WebsiteNameA.com/ <span class="br0">&#91;</span>R=<span style="">301</span>,L<span class="br0">&#93;</span>
&nbsp;
RewriteCond %<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span> ^WebsiteNameB.com$ <span class="br0">&#91;</span>NC<span class="br0">&#93;</span>
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span>$ http://www.WebsiteNameB.com/ <span class="br0">&#91;</span>R=<span style="">301</span>,L<span class="br0">&#93;</span></pre></td></tr></table></div>

<p>Save as .htaccess (be careful when using windows <a href="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/windowssave.jpg">not to add an extension</a>) and upload it to your root folder (/) This .htaccess-file still makes it possible to use sub domains like http://image.domain.com, keep in mind that in this example it doesn&#8217;t mather witch domain name you use. Both image.WebsiteNameA.com and image.WebsiteNameB.com will work for this example.</p>
<p>The next thing we will do is separate both domains. For this example I made 2 folders called websitea and websiteb in the www-folder. The names you use aren&#8217;t important, you could easily use &#8216;cake&#8217; and &#8216;beer&#8217; as long you change the names in your second .htaccess file. What brings us to .htaccess file number 2. Again, copy and modify the following code in a standard text-editor like notepad or gedit, the /websitea is the folder name of the corresponding domain:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="" style="font-family:monospace;">RewriteCond %<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span> ^www.WebsiteNameA.com$
RewriteCond %<span class="br0">&#123;</span>REQUEST_URI<span class="br0">&#125;</span> !/websitea
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span>$ /websitea/$1
&nbsp;
RewriteCond %<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span> ^www.WebsiteNameB.com$
RewriteCond %<span class="br0">&#123;</span>REQUEST_URI<span class="br0">&#125;</span> !/websiteb
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span>$ /websiteb/$1</pre></td></tr></table></div>

<p><a href="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/endvirtual.jpg" rel="lightbox[3]" title="End result VirtualDocumentroot"><img src="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/endvirtual.jpg" alt="" title="End result VirtualDocumentroot" width="134" height="135" class="alignleft size-full wp-image-12" /></a>And again you need to save the file as .htaccess but this time you upload the file in the www-folder! See the figure &#8220;End result VirtualDocumentroot&#8221; to get a clue.</p>
<p>Let me explain what this file does, whenever people visit website A or B, the server will get the files out the corresponding folder. In this case the server will get all the files for http://www.WebsiteNameA.com out folder /www/websitea and for http://www.WebsiteNameB.com out folder /www/websiteb. The cool thing about this is that the user won&#8217;t see it happen, unlike the redirect of http://WebsiteNameA.com to http://www.WebsiteNameA.com, you also don&#8217;t need to worry about complex url&#8217;s like http://www.WebsiteNameA.com/index.php?id=12&#038;other=test or http://www.WebsiteNameA.com/image/file.jpeg. If all the corresponding files are in the right folder, it will work.</p>
<p>One thing though, when you use full paths in your website&#8217;s you need to keep in mind that it&#8217;s now /www/websitea (or /www/websiteb), but normally this won&#8217;t be a problem in modern cms or blog engines like wordpress.</p>
<h3>DOCUMENTROOT.</h3>
<p>DocumentRoot is almost the same like VirtualDocumentroot, with the exception that your root folder is your www-folder and you don&#8217;t have sub domains. The good news is that there is less work to invisible redirect website.</p>
<p><a href="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/enddocum.jpg" rel="lightbox[3]" title="DocumentRoot"><img src="http://www.stijn-dhaese.be/blog/wp-content/uploads/2008/11/enddocum.jpg" alt="" title="DocumentRoot" width="114" height="74" class="alignright size-full wp-image-13" /></a>Lets get started, the first thing we need to do is to split or 2 website into 2 folder. All files from website A will go in folder websitea and all files of website B will go in folder websiteb (see image &#8216;DocumentRoot&#8217; for an example). The names of the folders aren&#8217;t important as long you change them in the .htacces file, what brings us to the next part: the .htaccess file. Copy and modify the following code in a standard text-editor like notepad or gedit:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="" style="font-family:monospace;">RewriteCond %<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span> ^www.WebsiteNameA.com$
RewriteCond %<span class="br0">&#123;</span>REQUEST_URI<span class="br0">&#125;</span> !/websitea
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span>$ /websitea/$1
&nbsp;
RewriteCond %<span class="br0">&#123;</span>HTTP_HOST<span class="br0">&#125;</span> ^www.WebsiteNameB.com$
RewriteCond %<span class="br0">&#123;</span>REQUEST_URI<span class="br0">&#125;</span> !/websiteb
RewriteRule ^<span class="br0">&#40;</span>.*<span class="br0">&#41;</span>$ /websiteb/$1</pre></td></tr></table></div>

<p>After you modified the file, save as .htacces and upload it into your root folder.</p>
<p>Let me explain what this file does, whenever people visit website A or B, the server will get the files out the corresponding folder. In this case the server will get all the files for http://www.WebsiteNameA.com out folder /websitea and for http://www.WebsiteNameB.com out folder /websiteb. The cool thing about this is that the user won&#8217;t see it happen, you also don&#8217;t need to worry about complex url&#8217;s like http://www.WebsiteNameA.com/index.php?id=12&#038;other=test or http://www.WebsiteNameA.com/image/file.jpeg. If all the corresponding files are in the right folder, it will work.</p>
<p>Good luck and if you have any questions, feel free to ask them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stijn-dhaese.be/2007/10/how-to-invisible-redirect-websites-in-apache-updated/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

