<?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>RLM &#187; URL Rewriting with mod_rewrite</title>
	<atom:link href="http://www.rlmseo.com/blog/category/web-development/url-rewriting-mod-rewrite/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rlmseo.com</link>
	<description></description>
	<lastBuildDate>Tue, 31 Jan 2012 03:37:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>htaccess Rewrite www</title>
		<link>http://www.rlmseo.com/blog/htaccess-rewrite-www/</link>
		<comments>http://www.rlmseo.com/blog/htaccess-rewrite-www/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 00:55:34 +0000</pubDate>
		<dc:creator>jcrens8392</dc:creator>
				<category><![CDATA[URL Rewriting with mod_rewrite]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>

		<guid isPermaLink="false">http://www.rlmseo.com/blog/?p=693</guid>
		<description><![CDATA[In this article I teach you how to use Apache's mod_rewrite to redirect all visitors to the www version of your domain. I'll also cover the reverse for those that want to send visitors to the non-www version only.]]></description>
			<content:encoded><![CDATA[<p>Although we&#8217;ve found that duplicate content rarely, if ever, results in an actual penalty against your website, there are still a number of reasons you&#8217;d want to redirect visitors to either one of the www-version or the non-www-version of your business&#8217; website.</p>
<p>Before I continue, let me clarify what I mean by www vs. non-www versions; I&#8217;ll use our domain as an example. For this domain, the www-version of the URL is &#8220;http://www.razorlightmedia.com&#8221; and the non-www version is &#8220;http://razorlightmedia.com&#8221;. The only difference is that one has &#8220;www&#8221; in it and the other does not. To see it in action, visit <a href="http://razorlightmedia.com" title="Non-www version of this site" onClick="window.open('http://rlmseo.com'); return false;">http://rlmseo.com</a> and watch your browser&#8217;s address bar as you&#8217;re redirected to http://www.rlmseo.com. It may happen too fast for you to see the change, but notice where you end up.</p>
<p>On most web servers, both the www and non-www versions are enabled by default, which means visitors can type either in the address bar of their browsers and find your site.</p>
<p>Now, some people will tell you that could result in a duplicate content penalty because the same page is being served through what are technically two different URLs. However, we&#8217;ve never encountered a single case of this happening on any search engines. Not to mention the fact that Google has come right out and said <a href="http://googlewebmastercentral.blogspot.com/2008/09/demystifying-duplicate-content-penalty.html" title="Google's take on duplicate content">they don&#8217;t penalize for duplicate content</a> &#8211; not strictly speaking at least.</p>
<p>So then, if not to avoid duplicate content issues, what&#8217;s the purpose of redirecting visitors to one of either the www or non-www version of your website URL? There are a few reasons, so lets get into those.</p>
<h2>Link Juice</h2>
<p>If you&#8217;ve spent any time reading about SEO, you probably know that a large part of what determines your rank in Google is the number and quality of links pointing to your site from other sites around the web. Although it&#8217;s nearly impossible to objectively identify the amount that each link helps you when examined individually, links pointing to both the www and non-www version of your website could spread the value of those links across the two URLs. We certainly don&#8217;t want this&#8230;we much prefer to have all of the <em>link juice</em> being passed to one single URL. By redirecting visitors to one or the other of the www or non-www versions of your URL using this technique, you&#8217;ll also redirect the search engines and any value they place on links to your site to the appropriate URL.</p>
<h2>Cookies</h2>
<p>In Yahoo&#8217;s great guide call <a href="http://developer.yahoo.com/performance/rules.html#cookie" title="Best Practices for Speeding up your Website">Best Practices for Speeding up your Website</a>, they briefly touch on a technique to avoid serving cookies with website components. The details aren&#8217;t important for the scope of this article, but one thing they mention is that when writing cookies on a non-www version of a domain you have no choice but to write to *.domain.com, which will encompass all subdomains as well. If you prefer not to have cookies written to all subdomains as well, you should use the www-version only so cookies can be set to the www domain.</p>
<h2>User Authentication</h2>
<p>This is a corollary of the Cookies explanation, so I&#8217;ll keep it brief. Some user authentication systems won&#8217;t recognize the user if he or she logs in via the non-www version when the system is set to accept users through the www version of the domain. Redirecting users to the appropriate version will prevent this issue.</p>
<h2>Implementing the htaccess rules</h2>
<p>We call these htaccess rules because they go into an htaccess file on your server. The setup is fairly simple: Create or edit the htaccess file in your document root directory and add one of the following rules to it:</p>
<h3>Update 4/27/2010</h3>
<p>Make sure the following line appears once before any rewrite rules in your htaccess file:</p>
<pre>RewriteEngine On</pre>
<h3>Redirect to www</h3>
<pre>RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]</pre>
<h3>Redirect to non-www</h3>
<pre>RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]</pre>
<p>Where &#8220;domain.com&#8221; is your actual domain name.</p>
<h2>Conclusion</h2>
<p>While htaccess rules &#8211; as you can see &#8211; can be complicated, these rules should work on any host which has apache&#8217;s mod_rewrite enabled and allows htaccess rewrite rules.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rlmseo.com/blog/htaccess-rewrite-www/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

