<?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>Peter Coughlin &#187; htaccess</title>
	<atom:link href="http://petercoughlin.com/category/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://petercoughlin.com</link>
	<description>Currently Focusing on WordPress Customization</description>
	<lastBuildDate>Mon, 12 Oct 2009 17:39:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Wordpress, Htaccess and Mod Rewrite</title>
		<link>http://petercoughlin.com/wordpress-htaccess-mod-rewrite/</link>
		<comments>http://petercoughlin.com/wordpress-htaccess-mod-rewrite/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 22:29:22 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://petercoughlin.com/?p=136</guid>
		<description><![CDATA[A while ago I was wrapping my head around the intricacies of mod_rewrite, especially as it relates to WordPress. I&#039;ve gotta say, it took me a long time to find the information that I needed, so here&#039;s the info that I would have liked, to maybe save you some trouble.
It all started because I was [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I was wrapping my head around the intricacies of mod_rewrite, especially as it relates to WordPress. I&#039;ve gotta say, it took me a long time to find the information that I needed, so here&#039;s the info that I would have liked, to maybe save you some trouble.</p>
<p>It all started because I was looking for an easy and simple (i.e. one that I can understand) way to automatically redirect any requests for &#034;www.petercoughlin.com&#034; to just &#034;petercoughlin.com&#034;.</p>
<p>Why? Well, it was all about trying to avoid duplicate content. There are plenty of great articles out there explaining duplicate content and why it&#039;s not good, so I won&#039;t go over it here. True, the search engines are getting better at it, but they&#039;re not there yet.<span id="more-136"></span></p>
<p>To be fair, this isn&#039;t just about WordPress &#8212; it applies to any website, so what I ended up looking at was how to do this with an htaccess file.</p>
<p>In short, you can place certain conditions and rules in your htaccess file, and these rules are processed whenever any page on your website is served up.</p>
<p>So, in my case I wanted to intercept all requests for &#034;http://www.petercoughlin.com/whatever.html&#034; and redirect them to &#034;http://petercoughlin.com/whatever.html&#034;. In other words, just strip the &#034;www.&#034; off the front. Here&#039;s the condition and rule that needed to go in my htaccess file to make it happen;</p>
<pre><code>RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://petercoughlin.com/$1 [R=301,L]</code></pre>
<p>I know, it looks like gobbledygook, but here&#039;s what it means. The first line is a condition, which uses {HTTP_HOST} to pick up the domain name of the request, and uses ^www\. to check whether it starts with &#034;www.&#034;</p>
<p>The second line uses ^(.*)$ to pick up everything after the domain name and drop it on the end of http://petercoughlin.com</p>
<p>The end result is that any page requests that begin with &#034;http://www.petercoughlin.com&#034; are automatically changed into page requests that begin with http://petercoughlin.com, no matter what page is being requested. How cool is that?</p>
<p>This means that fairly soon there&#039;ll be no more pages beginning with http://www.petercoughlin.com in the search engines. Awesome.</p>
<p>By the way, if you use this bit of code in your htaccess file, don&#039;t forget to change the &#034;petercoughlin.com&#034; bit to your own domain name :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://petercoughlin.com/wordpress-htaccess-mod-rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
