<?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>Cakephp.nu blog &#187; generic</title>
	<atom:link href="http://www.cakephp.nu/t/generic/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cakephp.nu</link>
	<description>Cake and cookies by Jippi</description>
	<lastBuildDate>Mon, 03 Nov 2008 15:36:32 +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>Generic non-www to www (and vice versa) 301 redirect using .htaccess</title>
		<link>http://www.cakephp.nu/quick-tip-generic-nonwww-www-vice-versa-301-redirect-htaccess</link>
		<comments>http://www.cakephp.nu/quick-tip-generic-nonwww-www-vice-versa-301-redirect-htaccess#comments</comments>
		<pubDate>Mon, 03 Nov 2008 15:33:06 +0000</pubDate>
		<dc:creator>Biesbjerg</dc:creator>
				<category><![CDATA[Cakephp]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[301]]></category>
		<category><![CDATA[generic]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.cakephp.nu/?p=23</guid>
		<description><![CDATA[
The problem: I&#8217;ve always hardcoded the domain name in my htaccess&#8217;es, requiring me to make changes each time I deploy a new website. The solution: Behold, an alternate, generic method of redirecting non-www to www and www to non-www, requiring no changes between deployments! Non-www to www RewriteCond %{HTTP_HOST} !^www\. RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L] www [...]
]]></description>
			<content:encoded><![CDATA[<h2>The problem:</h2>
<p>I&#8217;ve always hardcoded the domain name in my htaccess&#8217;es, requiring me to make changes each time I deploy a new website.</p>
<h2>The solution:</h2>
<p>Behold, an alternate, generic method of redirecting non-www to www and www to non-www, requiring no changes between deployments!</p>
<h3>Non-www to www</h3>
<pre>RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]</pre>
<h3>www to non-www</h3>
<pre>RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]</pre>
<h3>Bonus tip: Remove trailing slash from address line</h3>
<p>RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]</p>

	Tags: <a href="http://www.cakephp.nu/t/301" title="301" rel="tag">301</a>, <a href="http://www.cakephp.nu/t/generic" title="generic" rel="tag">generic</a>, <a href="http://www.cakephp.nu/t/htaccess" title="htaccess" rel="tag">htaccess</a>, <a href="http://www.cakephp.nu/t/redirect" title="redirect" rel="tag">redirect</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.cakephp.nu/quick-tip-generic-nonwww-www-vice-versa-301-redirect-htaccess/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
