<?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>Internet Business &#38; Marketing Strategy - Andy Beard &#187; Htaccess WordPress</title>
	<atom:link href="http://andybeard.eu/tag/htaccess-wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://andybeard.eu</link>
	<description>Internet Marketing, Lead Acquisition, Online Business Strategy and Social Media with Original Opinion and Loads of Attitude</description>
	<lastBuildDate>Sun, 12 Feb 2012 06:16:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>The Ultimate WordPress Htaccess File?</title>
		<link>http://andybeard.eu/612/the-ultimate-wordpress-htaccess-file.html</link>
		<comments>http://andybeard.eu/612/the-ultimate-wordpress-htaccess-file.html#comments</comments>
		<pubDate>Mon, 02 Apr 2007 16:11:32 +0000</pubDate>
		<dc:creator>Andy Beard</dc:creator>
				<category><![CDATA[blogging tips]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[mininet]]></category>
		<category><![CDATA[SEO Blog]]></category>
		<category><![CDATA[vre]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[Canonicalization]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[htaccess code]]></category>
		<category><![CDATA[Htaccess WordPress]]></category>
		<category><![CDATA[mod rewrite]]></category>
		<category><![CDATA[search engine optimization]]></category>
		<category><![CDATA[trailing slashes]]></category>

		<guid isPermaLink="false">http://andybeard.eu/2007/04/the-ultimate-wordpress-htaccess-file.html</guid>
		<description><![CDATA[<p>Canonicalization is a serious problem for webmasters, just read this <a href="http://www.mattcutts.com/blog/canonicalization-update/">latest entry by Matt Cutts</a> or  this <a href="http://www.johnon.com/267/trailing-slash-seo.html">great post from John Andrews</a>. However telling webmasters that they should fix these issues isn't enough, webmasters &#038; bloggers need solutions.</p>
<h3>In Search of the Ultimate Htaccess file</h3>
<p>A couple of months ago Alister Cameron posted a <a href="http://www.alistercameron.com/2007/01/12/two-wordpress-plugins-you-dont-need-and-shouldnt-use/">simple solution to .htaccess</a> such that you didn't need to use a plugin to convert URLs using www to URLs without.</p>
<p>At the time I suggested a couple of improvements, and also mentioned I would post about it here on my blog, hopefully to help</p>]]></description>
			<content:encoded><![CDATA[
<p>Canonicalization is a serious problem for webmasters, just read this <a href="http://www.mattcutts.com/blog/canonicalization-update/">latest entry by Matt Cutts</a> or  this <a href="http://www.johnon.com/267/trailing-slash-seo.html">great post from John Andrews</a>. However telling webmasters that they should fix these issues isn&#8217;t enough, <b>webmasters &#038; bloggers need solutions</b>.</p>
<h3>In Search of the Ultimate Htaccess file</h3>
<p>A couple of months ago Alister Cameron posted a <a href="http://www.alistercameron.com/2007/01/12/two-wordpress-plugins-you-dont-need-and-shouldnt-use/">simple solution to .htaccess</a> such that you didn&#8217;t need to use a plugin to convert URLs using www to URLs without.</p>
<p>At the time I suggested a couple of improvements, and also mentioned I would post about it here on my blog, hopefully to help develop what could be looked on as the &#8220;Ultimate&#8221; .htaccess file for WordPress, something you could just drop in your root folder and be done with it.<br />
For me the inclination was for multiple niche websites using WordPress as a CMS, so I really wanted to avoid anything that would make the content look dated.</p>
<div class="important" style="width:400px;">I am not an htaccess guru, and this is all cobbled together from code suggested by other people in various places<br />
<b>Before using any of this code, make a backup of your existing .htaccess, and be prepared to copy it back if testing proves something is broken.</b></div>
<p>Lets start off with the default .htaccess for WordPress once you turn on mod_rewrite for SEO friendly URLs</p>
<pre class="brush: plain; title: ; notranslate">
# BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;
# END WordPress
</pre>
<p>The first thing we want to do is get rid of the WWW if someone uses it. I know there are 2 schools of thought on whether URLs should have www by default or not, I prefer without and never type www unless I can&#8217;t access another site without it (broken htaccess).</p>
<p>Secondly we also want to get rid of trailing slash problems</p>
<p>The base rules that Alister first suggested were</p>
<pre class="brush: plain; title: ; notranslate">
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.alistercameron.com$ [NC]
RewriteRule ^(.*)$ http://www.alistercameron.com/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
&lt;/IfModule&gt;
</pre>
<p>However we want this to be the <b>Ultimate htaccess code</b>, thus we don&#8217;t want to have to enter the domain name. I am not sure whether this will work if you have multiple blogs in sub-folders.</p>
<p>In this code we are using HTTP_HOST rather than adding a URL manually to every .htaccess file you create. If you are setting up 50 blogs (niche marketers do things like this, and fill them with unique original content &#8211; not everyone creates splogs) then being able to use one default file is a major advantage.</p>
<pre class="brush: plain; title: ; notranslate">
# If subdomain www exists, remove it first
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</pre>
<p>Can we improve on the trailing slashes code?</p>
<p>Possibly&#8230;</p>
<p>A while ago I was also reading a post over on Aaron Walls SEO Book blog. Within the comments were suggestions with improvements to the code Aaron suggested.<br />
Finding the exact reference is a problem as it wasn&#8217;t <a href="http://www.seobook.com/archives/001714.shtml">on this thread</a></p>
<p>Searching on a phrase in the code these days only brings up a reference on Alister&#8217;s blog where I mentioned it in the comments, so I have no idea who to attribute this htaccess code to.</p>
<pre class="brush: plain; title: ; notranslate">
# If requested resource does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# and does not end with a period followed by a filetype
RewriteCond %{REQUEST_URI} !..+$
# and does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# then add a trailing slash and redirect
RewriteRule (.*) $1/ [R=301,L]
&lt;/IfModule&gt;
</pre>
<p><b>I am not a htaccess guru</b>, but this seems to take into account more potential situations such as files to download.</p>
<p>If you put all this code together you end up with something like this</p>
<pre class="brush: plain; title: ; notranslate">
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
# If subdomain www exists, remove it first
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# If requested resource does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# and does not end with a period followed by a filetype
RewriteCond %{REQUEST_URI} !..+$
# and does not end with a slash
RewriteCond %{REQUEST_URI} !/$
# then add a trailing slash and redirect
RewriteRule (.*) $1/ [R=301,L]
&lt;/IfModule&gt;

# BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;

# END WordPress
</pre>
<p><strong>So can anyone offer any constructive improvements?</strong></p>
<p>If you offer improvements, please provide code samples and explain exactly why it is an improvement so people can learn from it (as I said I am a newbie at this)<br />
Code can be entered using code tags in square brackets.</p>
<div class="topsy_widget_data topsy_theme_brick-red" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fandybeard.eu%252F612%252Fthe-ultimate-wordpress-htaccess-file.html%22%2C%20%22shorturl%22%3A%20%22http%3A%2F%2Fbit.ly%2Fi6jt8F%22%2C%20%22style%22%3A%20%22small%22%2C%20%22title%22%3A%20%22The%20Ultimate%20Wordpress%20Htaccess%20File%3F%22%20%7D);"></div>


	Tags: <a href="http://andybeard.eu/tag/blogging" title="blogging" rel="tag">blogging</a>, <a href="http://andybeard.eu/tag/blogging-tips" title="blogging tips" rel="tag">blogging tips</a>, <a href="http://andybeard.eu/tag/canonicalization" title="Canonicalization" rel="tag">Canonicalization</a>, <a href="http://andybeard.eu/tag/htaccess" title="htaccess" rel="tag">htaccess</a>, <a href="http://andybeard.eu/tag/htaccess-code" title="htaccess code" rel="tag">htaccess code</a>, <a href="http://andybeard.eu/tag/htaccess-wordpress" title="Htaccess WordPress" rel="tag">Htaccess WordPress</a>, <a href="http://andybeard.eu/tag/mod-rewrite" title="mod rewrite" rel="tag">mod rewrite</a>, <a href="http://andybeard.eu/tag/search-engine-optimization" title="search engine optimization" rel="tag">search engine optimization</a>, <a href="http://andybeard.eu/tag/seo" title="SEO Blog" rel="tag">SEO Blog</a>, <a href="http://andybeard.eu/tag/trailing-slashes" title="trailing slashes" rel="tag">trailing slashes</a><br />
]]></content:encoded>
			<wfw:commentRss>http://andybeard.eu/612/the-ultimate-wordpress-htaccess-file.html/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: basic
Database Caching 30/43 queries in 0.008 seconds using disk: basic
Object Caching 625/646 objects using disk: basic
Content Delivery Network via cdn5.andybeard.name

Served from: andybeard.eu @ 2012-02-13 07:13:00 -->
