<?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>Nerdaphernalia &#187; caching</title>
	<atom:link href="http://striderweb.com/nerdaphernalia/tag/caching/feed/" rel="self" type="application/rss+xml" />
	<link>http://striderweb.com/nerdaphernalia</link>
	<description>"It's All Geek To Me"</description>
	<lastBuildDate>Wed, 21 Dec 2011 18:51:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Override single WordPress pages with .htaccess</title>
		<link>http://striderweb.com/nerdaphernalia/2008/03/override-single-wordpress-pages-with-htaccess/</link>
		<comments>http://striderweb.com/nerdaphernalia/2008/03/override-single-wordpress-pages-with-htaccess/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 19:40:05 +0000</pubDate>
		<dc:creator>Stephen R</dc:creator>
				<category><![CDATA[GUI Goodness]]></category>
		<category><![CDATA[Tha Interweb]]></category>
		<category><![CDATA[Webcraft]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://striderweb.com/nerdaphernalia/2008/03/override-single-wordpress-pages-with-htaccess/</guid>
		<description><![CDATA[Until recently, Striderweb.com was made up of static HTML files except for the blog sections themselves. After a while, I decided I wanted to run the entire site off of WordPress, but to do that I realized that the existing pages would have issues until I had converted all of them by remaking them inside [...]]]></description>
			<content:encoded><![CDATA[<p>Until recently, Striderweb.com was made up of static HTML files except for the blog sections themselves.  After a while, I decided I wanted to run the entire site off of WordPress, but to do that I realized that the existing pages would have issues until I had converted <em>all of</em> them by remaking them inside the WordPress hierarchy.  (The &#8220;hard&#8221; <code>.htm</code> files would conflict with WordPress Pages that have a similar &#8220;virtual&#8221; location.)</p>
<p>After a bit of tinkering, I figured out that this could be fixed with a small change to the <code>mod_rewrite</code> section that WordPress puts into the site&#8217;s <code>.htaccess</code> file.  As a happy side effect, <span class="pullquote">this system also allows you to manually cache a particular page</span>, such as if you are suddenly getting hammered by an Instalanche or a Digg link.</p>
<p>Open your site&#8217;s <code>.htaccess</code> and you should see the following, which was put there by WordPress:</p>
<pre><code lang-html"># 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</code></pre>
<p>Change it to this:</p>
<pre><code lang-html">&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
#	RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.htm !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . /index.php [L]
&lt;/IfModule&gt;

# BEGIN WordPress
# END WordPress</code></pre>
<p>With this modification to the basic WordPress .htaccess rewrite, you can now put a hard-coded file in a particular place in the hierarchy.</p>
<h3>How Does it Work?</h3>
<p>For an example, let&#8217;s look at this page in a typical WordPress site:</p>
<p><code>http://example.com/archives/123</code></p>
<p>With WordPress running the site, there is no <em>actual</em> folder called &#8220;archives&#8221;, and in turn no actual &#8220;123&#8243; folder or file.  WordPress is creating the pages on the fly as they are called.  Normally, if you were to actually put a folder called &#8220;archives&#8221; in that location, WordPress would hand control over to the actual directory.</p>
<p>We, however, don&#8217;t want that.  We want WordPress to relinquish control with <code>/archives/123</code>, but <em>not</em> with, say, <code>/archives/122</code>, or even just <code>/archives</code>.</p>
<p>Our new <code>.htaccess</code> code above changes how WordPress handles &#8220;real&#8221; directories.  With the new code, it only gives up control if the directory in question contains a file named either &#8220;<code>index.htm</code>&#8221; or &#8220;<code>index.php</code>&#8221;</p>
<p>So, to manually override <code>/archives/123</code>, we create an &#8220;archives&#8221; directory at the root of the site.  In &#8220;archives&#8221;, we create a &#8220;123&#8243; folder; and inside <em>that</em>, we create either <code>index.htm</code> or <code>index.php</code> that contains the override page.</p>
<p>Note that the base <code>/archive</code> directory, and any other pages or posts within it (e.g. <code>/archives/122</code>), are still controlled as normal by WordPress.</p>
<p>Another part of the reason I did this was that I have a page on this site that is a demonstration of a CSS method, and I wanted the demo page to be an independent page not run by WordPress (specifically, not complicated by the WordPress template).</p>
<p>You can see it in action here:</p>
<p><a href="/nerdaphernalia/webcraft/complexspiral/">http://striderweb.com/nerdaphernalia/webcraft/complexspiral/</a></p>
<p>Note that <a href="/nerdaphernalia/webcraft/">http://striderweb.com/nerdaphernalia/webcraft/</a> is still run normally by the WordPress install that runs the rest of Nerdaphernalia.  If I wanted to, I could also make sub-pages of the &#8220;ComplexSpiral&#8221; page that are also run by WordPress.</p>
<p>You will also note that the &#8220;ComplexSpiral&#8221; page is listed in the Page listing created by WordPress.  That is, <span class="pullquote">the WordPress system knows that there&#8217;s a page there, even though it&#8217;s not running it</span>.  How did I do that?  Quite simply, actually.  I just made a page with the same address within WordPress &#8212; a &#8220;placeholder&#8221; of sorts.  It doesn&#8217;t matter what&#8217;s in the <a href="#fnote59_1">placeholder page<sup>1</sup></a>, because we&#8217;ll never see it &#8212; it&#8217;s overridden by the hard-coded page we created.  But it creates the entry within the WordPress system and thus we see a link to the page within the normal WordPress page listings.</p>
<p>(And yes, you could use it to override a particular post, too.)</p>
<p>There is one final step, and this is <em>important</em>:  Be sure to change the permissions on your .htaccess file so that WordPress doesn&#8217;t overwrite it with the defaults.</p>
<p>Enjoy!</p>
<div id="fnote59_1" class="fnote">1: I generally fill it with: &#8220;This text is a placeholder.  If you&#8217;re reading this, something&#8217;s wrong. Please let me know so I can fix it.&#8221;</div>
<hr />
© <a href="http://striderweb.com/">Stephen Rider</a> 2008
<p>This article was originally published at <a href="http://striderweb.com/nerdaphernalia">Nerdaphernalia</a>.  <a href="http://planetwordpress.planetozh.com/" rel="nofollow">Planet WordPress</a> is authorized to reproduce WordPress-related entries.  <em>If you're reading this at any other web site, the site owner is stealing copyrighted work.  Please visit the original page:</em></p>

<small><a href="http://striderweb.com/nerdaphernalia/2008/03/override-single-wordpress-pages-with-htaccess/">Permalink to Override single WordPress pages with .htaccess</a></small>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://striderweb.com/nerdaphernalia/2008/03/override-single-wordpress-pages-with-htaccess/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

