<?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>Nicolas Kuttler &#187; duplicate content</title>
	<atom:link href="http://www.nkuttler.de/tag/duplicate-content/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nkuttler.de</link>
	<description>WordPress Services, IT Services</description>
	<lastBuildDate>Wed, 28 Jul 2010 23:49:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Redirecting all subdomains to the main domain</title>
		<link>http://www.nkuttler.de/2009/01/11/redirecting-all-subdomains-to-the-main-domain/</link>
		<comments>http://www.nkuttler.de/2009/01/11/redirecting-all-subdomains-to-the-main-domain/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 14:29:30 +0000</pubDate>
		<dc:creator>nicolas</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[duplicate content]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[virtual hosts]]></category>

		<guid isPermaLink="false">http://www.nkuttler.de//?p=313</guid>
		<description><![CDATA[How to redirect a subdomain to the main domain, or a domain to a subdomain. Redirect domain.com to www.domain.com.]]></description>
			<content:encoded><![CDATA[<p>Using the canonical hostname for websites isn&#8217;t an obvious problem. After all, who really cares if your site is accessible at <tt>www.domain.com</tt> and <tt>domain.com</tt>? Search engines, for example, could penalize you for having the same content on both domains. I think that today they are smart enough to discover this specific case though.<span id="more-313"></span></p>
<p>Another problem can happen when you use cookies. If not done correctly, your user&#8217;s cookie won&#8217;t be available to the website when they were stored under <tt>www.domain.com</tt> and he uses <tt>domain.com</tt> the next time he visits. See the <a href="http://cgi.netscape.com/newsref/std/cookie_spec.html">cookie specs</a> for more details.</p>
<p>A quick research led me to a solution for apache that I didn&#8217;t like too much. It involves using <tt>mod_rewrite</tt>. <tt>mod_rewrite</tt> is a great tool, but there&#8217;s a better solution for redirecting to your main domain from subdomains or second level domains. Simply use a catchall virtual host in your apache host configuration file(s) to do the redirects. This will solve all the SEO, caching and cookie issues, and it will save some CPU cycles compared to the <tt>mod_rewrite</tt> or higher level solutions.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># NameVirtualHost *:80</span>
&nbsp;
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> www.domain.com
    <span style="color: #adadad; font-style: italic;"># This is your main domain</span>
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;
&nbsp;
&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> domain.com
    <span style="color: #00007f;">ServerAlias</span> *.domain.com
    <span style="color: #adadad; font-style: italic;"># This is to make sure that foo.domain.com gets redirected too</span>
    <span style="color: #adadad; font-style: italic;"># If you want to use more virtual hosts on subdomains,</span>
    <span style="color: #adadad; font-style: italic;"># just define them earlier</span>
    <span style="color: #00007f;">Redirect</span> / http://www.domain.com/
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>Please refer to the <a href="http://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect">mod alias docs</a> to decide which <tt>Redirect</tt> you need, this example uses a 302.</p>
<p>For lighttpd you can use this:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$HTTP</span><span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;host&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=~</span> <span style="color: #ff0000;">&quot;domain<span style="color: #000099; font-weight: bold;">\.</span>com&quot;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$HTTP</span><span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;host&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #ff0000;">&quot;www.domain.com&quot;</span> <span style="color: #009900;">&#123;</span>
        url<span style="color: #339933;">.</span>redirect <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
            <span style="color: #ff0000;">&quot;^(.*)$&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;http://www.domain.com$1&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>By the way, if you&#8217;re an <tt>IIS</tt> user, you might want to read <a href="http://www.xoc.net/works/tips/domain.asp">this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nkuttler.de/2009/01/11/redirecting-all-subdomains-to-the-main-domain/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
