<?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>This Life of Brian &#187; .htaccess</title>
	<atom:link href="http://life-of-brian.com/tag/htaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://life-of-brian.com</link>
	<description>My name is Brian.  Welcome to my life.</description>
	<lastBuildDate>Tue, 03 Jan 2012 03:09:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to Use .htaccess to Remove www From Inbound URLs</title>
		<link>http://life-of-brian.com/2008/12/how-to-use-htaccess-to-remove-www-from-inbound-urls/</link>
		<comments>http://life-of-brian.com/2008/12/how-to-use-htaccess-to-remove-www-from-inbound-urls/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 23:44:24 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Nerds at Work]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[.htaccess]]></category>

		<guid isPermaLink="false">http://life-of-brian.com/?p=861</guid>
		<description><![CDATA[On most modern web servers, you can access the same page with or without the &#8220;www&#8221; before the domain name. You may be tempted, then, to just let well enough alone and let some people access your site with the &#8216;www&#8217; and let some people access it without the &#8216;www.&#8217;  Well, there are some compelling [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://life-of-brian.com/wp-content/uploads/2008/12/www-symbol.jpg"><img class="alignright" title="WWW Symbol" src="http://life-of-brian.com/wp-content/uploads/2008/12/www-symbol-300x180.jpg" alt="Simple image of the letters 'www' in gray, on a white background, with shadows." /></a>On most modern web servers, you can access the same page with or without the &#8220;www&#8221; before the domain name. You may be tempted, then, to just let well enough alone and let some people access your site with the &#8216;www&#8217; and let some people access it without the &#8216;www.&#8217; </p>
<p>Well, there are some compelling reasons why that is a <strong>bad</strong> idea. I&#8217;d try to make you feel guilty about that decision, if it weren&#8217;t for the fact that I&#8217;ve been too lazy up until now to do it myself. Oops.</p>
<p>For those of you that are impatient, I&#8217;ll deal with the technical stuff first. Then, we&#8217;ll take a look at <strong>why</strong> you shouldn&#8217;t be using the &#8216;www&#8217; subdomain.</p>
<h3>How to Use .htaccess to Remove the &#8216;www&#8217; From Inbound URLs</h3>
<p>This can be accomplished with a simple .htaccess mod_rewrite redirect.</p>
<p>First, let&#8217;s take a look at the code as it appears in my .htaccess file.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
&nbsp;
<span style="color: #adadad; font-style: italic;">#redirect from www.life-of-brian.com to life-of-brian.com</span>
<span style="color: #00007f;">RewriteCond</span> %{HTTP_HOST} ^www.life-of-brian.com$ [NC]
<span style="color: #00007f;">RewriteRule</span> ^(.*)$ http://life-of-brian.com/$<span style="color: #ff0000;">1</span> [R=<span style="color: #ff0000;">301</span>,L]</pre></div></div>

<p>The first line turns on the mod_rewrite engine. You&#8217;ll need this at the beginning of your .htaccess file if you plan to use any rewrites.</p>
<p>The &#8220;RewriteCond&#8221; line tells the server what to look out for. In this case, the simple regex [<strong>^www.life-of-brian.com$</strong>] grabs any expression that starts with <strong>www.life-of-brian.com</strong>. The remainder of the expression &#8211; such as the trailing part of the URL &#8211; is stored in the variable $1.</p>
<p>The &#8220;RewriteRule&#8221; line tells the server where it should send the user. It rewrites the entire URL, starting with the domain without the www [<strong>http://life-of-brian.com</strong>] and then it appends the trailing portion of the URL [<strong>$1</strong>].</p>
<p>How do you adapt this for your own site? Simple.</p>
<p>In the RewriteCond, change <strong>www.life-of-brian.com</strong> to your own domain (including the www). Then, in the RewriteRule line, replace <strong>http://life-of-brian.com</strong> wth your own domain.</p>
<p>It&#8217;s also a good idea to wrap the whole snippet with the tags &lt;IfModule mod_rewrite.c&gt; and &lt;/IfModule&gt;.</p>
<p>Here&#8217;s the entire .htaccess file rewritten for the domain <strong>mydomain.com</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
&nbsp;
<span style="color: #adadad; font-style: italic;">#redirect from www.mydomain.com to mydomain.com</span>
<span style="color: #00007f;">RewriteCond</span> %{HTTP_HOST} ^www.mydomain.com$ [NC]
<span style="color: #00007f;">RewriteRule</span> ^(.*)$ http://mydomain.com/$<span style="color: #ff0000;">1</span> [R=<span style="color: #ff0000;">301</span>,L]</pre></div></div>

<p>If you&#8217;re using this with an existing .htaccess file, put this snippet at the very beginning. For example, I use .htaccess to create pretty URLs for my WordPress posts. I placed this snippet before the snippet that was automatically generated by WordPress.</p>
<h3>Ok. So Why Remove the &#8216;www&#8217;?</h3>
<p>Let&#8217;s focus on two main reasons why you shouldn&#8217;t use &#8211; and why should encourage your users not to use &#8211; the www subdomain. The first reason has to do with form and semantics, while the second one might have benefits in terms of SEO and SERP.</p>
<p><strong>The Semantics Argument.</strong> If you surf around web design blogs, you&#8217;ll see a lot of talk about coding semantically correct and standards meeting sites. There&#8217;s a belief that doing things <strong>the right</strong> way is inherently good &#8211; even if there may not be a lot of hard evidence that you benefit from it.</p>
<p>Likewise, there&#8217;s an argument to be made for the disuse of the &#8216;www&#8217; subdomain. It is no longer needed, it is depracated, and it should therefore go by the wayside. I stumbled on the site <a href="http://no-www.org/">no-www</a> today, and found a great quote to summarize this position:</p>
<blockquote><p>Succinctly, use of the www subdomain is redundant and time consuming to communicate. The internet, media, and society are all better off without it.</p></blockquote>
<p>In most cases, there is no need to use the www subdomain. Your browser and the web server assume that you&#8217;re looking for web content &#8211; so they serve it up automatically. Including the &#8216;www&#8217; is therefore redundant.</p>
<p>Since the &#8216;www&#8217; is no longer necessary, it just seems like the right thing to do to not use it. You should therefore gently suggest to your users that they stop typing in those letters for no reason.</p>
<p><strong>The SEO Argument.</strong> If you want visitors to find your website through a search engine, you know at least a bit about SEO (Search Engine Optimization) and SERP (Search Engine Results Page) placement. You know that things like links to your site help improve your SEO and SERP &#8211; and ultimately bring more users to your site.</p>
<p>So what happens if the search engine thinks that <strong>www.mydomain.com/landing-page.html</strong> is different from <strong>mydomain.com/landing-page.html</strong>? If the inbound links to your site are split between these two domains, the search engine might miscalculate the number of links coming to your page &#8211; thus negatively impacting your SEO and SERP.</p>
<p>The htaccess mod_rewrite redirect that we used above automatically sends the search engine spider to one page &#8211; no matter URL the inbound link provided. There&#8217;s no chance that the search engine will get confused and consider the two URLs to be separate pages.</p>
<p>Considering it takes only a couple minutes to create an appropriate .htaccess file, I think it&#8217;s time well spent if it has even the slightest impact on your SEO and SERP.</p>
]]></content:encoded>
			<wfw:commentRss>http://life-of-brian.com/2008/12/how-to-use-htaccess-to-remove-www-from-inbound-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirecting WordPress Feeds to Feedburner</title>
		<link>http://life-of-brian.com/2008/12/redirecting-wordpress-feeds-to-feedburner/</link>
		<comments>http://life-of-brian.com/2008/12/redirecting-wordpress-feeds-to-feedburner/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 00:30:10 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[CMS Tricks]]></category>
		<category><![CDATA[Nerds at Work]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Feedburner]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://life-of-brian.com/?p=624</guid>
		<description><![CDATA[Continuing my attempts to improve this site, I decided to embark on creating feedburner feeds for each sub-site. Then, I needed to re-direct my WordPress feed files to feedburner.  Turns out it wasn&#8217;t quite as easy as I hoped. There&#8217;s a WordPress plugin available to redirect your feed to Feedburner, but this only redirects the [...]]]></description>
			<content:encoded><![CDATA[<p><a rel="attachment wp-att-626" href="http://life-of-brian.com/2008/12/redirecting-wordpress-feeds-to-feedburner/wordpress-and-feedburner/"><img class="alignright" title="Wordpress and Feedburner Logos" src="http://life-of-brian.com/wp-content/uploads/2008/12/wordpress-and-feedburner-300x164.jpg" alt="Image containing the WordPress and Feedburner logos." /></a>Continuing my attempts to improve this site, I decided to embark on creating feedburner feeds for each sub-site. Then, I needed to re-direct my WordPress feed files to feedburner. </p>
<p>Turns out it wasn&#8217;t quite as easy as I hoped. There&#8217;s a <a href="http://www.google.com/support/feedburner/bin/answer.py?answer=78483&amp;topic=13252">WordPress plugin available to redirect your feed</a> to Feedburner, but this only redirects the main feed and the comments feed. No dice for categories.</p>
<p>I found a few people suggesting an alternative: .htaccess rewrites. I never liked working with .htaccess, mostly because I never liked working with regex. But what are ya gonna do?</p>
<h3>An .htaccess Alternative to the Plugin</h3>
<p>I found an example of a <a href="http://perishablepress.com/press/2008/03/25/redirect-wordpress-feeds-to-feedburner-via-htaccess-redux/">.htaccess solution at Persihable Press</a>.</p>
<p>For a full explanation, head over to the original article. But in the meantime, here&#8217;s the .htaccess code he suggested:</p>

<div class="wp_syntax"><div class="code"><pre class="reg" style="font-family:monospace;"># temp redirect all wordpress feeds to feedburner
&nbsp;
 RewriteEngine on
 RewriteCond %<span style="color: #000000;">&#123;</span>REQUEST_URI<span style="color: #000000;">&#125;</span>      ^/?<span style="color: #000000;">&#40;</span>feed.*|comments.*<span style="color: #000000;">&#41;</span>        <span style="color: #000000;">&#91;</span>NC<span style="color: #000000;">&#93;</span>
 RewriteCond %<span style="color: #000000;">&#123;</span>HTTP_USER_AGENT<span style="color: #000000;">&#125;</span> !^.*<span style="color: #000000;">&#40;</span>FeedBurner|FeedValidator<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#91;</span>NC<span style="color: #000000;">&#93;</span>
 RewriteRule ^feed/?.*$          http://feeds.feedburner.com/perishablepress         <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span>
 RewriteRule ^comments/?.*$      http://feeds.feedburner.com/perishablepresscomments <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span></pre></div></div>

<p>As I understand it, this is more or less a three step process.</p>
<p>First, the regex catches all requests for a URI that includes feed or comments (i.e. your RSS feed). Then, it checks if the user agent is FeedBurner. The FeedBurner bot is allowed to access the original feed, but everybody else should be tossed over to the Feedburner site.</p>
<p>Finally, it sends the user to the appropriate Feedburner URL, based on the request URI.</p>
<h3>Adding Category Feeds</h3>
<p>That, of course, does the same thing as the plugin. It redirects the site feed and the comments feed, but it doesn&#8217;t help you redirect your categories.</p>
<p>For me, each parent category is like it&#8217;s own site, so that doesn&#8217;t help. I&#8217;d like you to be able to subscribe to the &#8220;Nerds at Work&#8221; feed about web development without being bored by all my ranting on education.</p>
<p>Luckily, somebody <a href="http://perishablepress.com/press/2008/03/25/redirect-wordpress-feeds-to-feedburner-via-htaccess-redux/#comment-69064">commented on the original article</a> and left a suggestion as to how to redirect the category feeds. I used that to create my own .htaccess file, and everything seems to work hunky-dory.</p>
<p>You don&#8217;t need to re-write any of the conditions, because that regex will already flag the category feeds. All you need to do is add a few extra rewrite rules, based on the new URIs and provide the appropriate Feedburner URL.</p>
<p>In general, that rewrite rule should look like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="reg" style="font-family:monospace;">RewriteRule ^category/nerds-at-work/feed/?.*$
  http://feeds.feedburner.com/thislifeofbrian-work <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span></pre></div></div>

<p>Replace &#8216;nerds-at-work&#8217; with your own category slug, and replace the full URL with the URL to your Feedburner feed.</p>
<p>I had some trouble with this at first, but I think the problem was due to positioning. In the end, I added all of the category specific re-write rules <strong>after</strong> the general rewrite rule. When I placed them first, it didn&#8217;t work. Might just be that I&#8217;m a regex/htaccess newb, though.</p>
<p>Here&#8217;s the full .htaccess file that I&#8217;m using, including what WordPress generated for the pretty-urls.</p>

<div class="wp_syntax"><div class="code"><pre class="reg" style="font-family:monospace;"># Redirect Wordpress Feeds to Feedburner
&nbsp;
RewriteEngine on
RewriteCond %<span style="color: #000000;">&#123;</span>REQUEST_URI<span style="color: #000000;">&#125;</span> ^/?<span style="color: #000000;">&#40;</span>feed.*<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#91;</span>NC<span style="color: #000000;">&#93;</span>
RewriteCond %<span style="color: #000000;">&#123;</span>HTTP_USER_AGENT<span style="color: #000000;">&#125;</span> !^.*<span style="color: #000000;">&#40;</span>FeedBurner|FeedValidator<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#91;</span>NC<span style="color: #000000;">&#93;</span>
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-sitewide <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span>
RewriteRule ^category/nerds-at-work/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-work <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span>
RewriteRule ^category/nerds-at-play/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-play <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span>
RewriteRule ^category/teach-them-well/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian-teach <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span>
RewriteRule ^category/life-of-brian/feed/?.*$ http://feeds.feedburner.com/thislifeofbrian <span style="color: #000000;">&#91;</span>L,NC,R<span style="color: #000000;">=</span>302<span style="color: #000000;">&#93;</span>
&nbsp;
# BEGIN WordPress
&nbsp;
RewriteEngine On
RewriteBase /
RewriteCond %<span style="color: #000000;">&#123;</span>REQUEST_FILENAME<span style="color: #000000;">&#125;</span> !-f
RewriteCond %<span style="color: #000000;">&#123;</span>REQUEST_FILENAME<span style="color: #000000;">&#125;</span> !-d
RewriteRule . /index.php <span style="color: #000000;">&#91;</span>L<span style="color: #000000;">&#93;</span>
&nbsp;
# END WordPress</pre></div></div>

<p>Good luck, and hopefully you&#8217;re more experienced with htaccess/regex than I am.</p>
]]></content:encoded>
			<wfw:commentRss>http://life-of-brian.com/2008/12/redirecting-wordpress-feeds-to-feedburner/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

