<?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>Zenovation's Blog &#187; server</title>
	<atom:link href="http://zenovations.com/blog/tag/server/feed/" rel="self" type="application/rss+xml" />
	<link>http://zenovations.com/blog</link>
	<description>A blog about web design, programming, hosting, and virtualmin hacks</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:01:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Redirect domain to subfolder on different site</title>
		<link>http://zenovations.com/blog/2009/04/redirect-domain-to-subfolder-on-different-site/</link>
		<comments>http://zenovations.com/blog/2009/04/redirect-domain-to-subfolder-on-different-site/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 19:35:11 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://zenovations.com/blog/?p=41</guid>
		<description><![CDATA[Wanted to redirect our old standby, pastebin.zentrack.net to the new location, dev.zentrack.net/pastebin. Took a bit of mojo to find the answer to that problem. I decided on using apache and bypass virtualmin&#8217;s admin tools. The &#8220;Rewrite&#8221; Approach Here is an approach using a rewrite rule, that preserves files and query parms from the original entry. [...]]]></description>
			<content:encoded><![CDATA[<p>Wanted to redirect our old standby, pastebin.zentrack.net to the new location, dev.zentrack.net/pastebin. Took a bit of mojo to find the answer to that problem. I decided on using apache and bypass virtualmin&#8217;s admin tools.</p>
<h3>The &#8220;Rewrite&#8221; Approach</h3>
<p>Here is an approach using a rewrite rule, that preserves files and query parms from the original entry. This takes widgets.mysite.com/files/?id=20 and redirects it to www.mysite.com/widgets/files/?id=20:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p41code3'); return false;">View Code</a> LANGUAGE</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p413"><td class="code" id="p41code3"><pre class="language" style="font-family:monospace;">RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.mainsite\.com
RewriteRule (.*) http://www.mainsite.com/subdirectory$1 [L,R=permanent]</pre></td></tr></table></div>

<p><code>%{HTTP_HOST}</code> is an apache variable that refers to the current domain entered in browser.<br />
<br /><code>(www\.)</code> makes it possible to redirect widgets.mysite.com or www.widgets.mysite.com.<br />
<br /><code>/subdirectory </code>is where you specify which directory the redirect drops them in.<br />
<br /><code>(/.+)?</code> bit is what adds on any details after the url.<br />
<br /><code>[L, R=permanent]</code> is based on <a href="http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteCond">Apache&#8217;s RewriteCond options</a>, and tells apache we actually want to change the url in the browser, instead of just showing the correct page at this url.</p>
<h3>The &#8220;Redirect&#8221; Approach</h3>
<p>A simpler approach is to create a hard redirect like the following. This takes widgets.mysite.com/files/?id=20 and redirects it to www.mysite.com/widgets/:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p41code4'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p414"><td class="code" id="p41code4"><pre class="ini" style="font-family:monospace;">ServerAlias subdomain.mainsite.com
RewriteEngine on
RewriteCond %<span style="">&#123;</span>HTTP_HOST<span style="">&#125;</span> ^subdomain.mainsite.com$ <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>OR<span style="">&#93;</span></span> 
RewriteCond %<span style="">&#123;</span>HTTP_HOST<span style="">&#125;</span> ^www.subdomain.mainsite.com$ 
RewriteRule ^<span style="">&#40;</span>.*<span style="">&#41;</span>$ http://www.mainsite.com/subdirectory <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>R<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">301,L<span style="">&#93;</span></span></span></pre></td></tr></table></div>

<p>This goes into the apache config, inside mainsite.com&#8217;s VirtualHost directive.<br />
<br /><code>ServerAlias</code> directive allows the main site to also accept queries for the subdomain.<br />
You may also need to add a DNS entry, depending on your setup.<br />
<br /><code>RewriteCond </code>with www.subdomain.mainsite.com is optional and recommended&#8211;if you remove it, also remove the <code>[OR]</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zenovations.com/blog/2009/04/redirect-domain-to-subfolder-on-different-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

