WordPress: Creating a Static Directory

While I’m very happy with how WordPress2 handles dynamic page generation with customized permalinks and the like, that doesn’t quite suite my needs for storing static content in a “real” directory.

From time to time I find myself wanting to drop files into a directory under the root location of WordPress. Occasionally it’s nice to upload and link to source code, compressed archives, demo applications or even just random files.

If you’ve ever tried this you realize of course that Wordpress assumes all links coming to anything at or below the root location is a link it should dynamically handle and generate appropriately. As such, creating a location such as “…\mydirectory” under the WP root will result in WP 404 message.

Static Jack

I tried out Jack Born’s “Static Jack” plugin which is supposed to allow you the ability to basically add a redirect rule for static pages.

This worked find for a while but when I leaned on it a bit I found that it wasn’t quite designed to accomplish what I needed. Don’t get me wrong, I think this is a great plugin (thanks Jack) but it wasn’t specifically made to address my particular need.

The plugin handled a few things differently than I desired such as not being 100% compatible with IE and not allowing the browser to render txt documents correctly.

Present Solution

While I didn’t necessarily look forward to messing with the .htaccess file, I knew that the problem could probably be solved with inserting a line or two. Thanks to a helpful article by HÃ¥vard Stranden, the line I ended up adding was:

RewriteCond %{REQUEST_URI} !^/mydirectory/?

Adding the /? after “mydirectory” allows any directories beneath it to also serve “static” pages.

The WordPress section of my .htaccess now looks like this


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/mydirectory/?
RewriteRule . /index.php [L]

I hope someone else finds this helpful.

One Comment

  1. jameswillisisthebest
    Posted September 8, 2007 at 2:21 pm | Permalink

    This is my first post
    just saying HI

2 Trackbacks

  1. [...] i ndustrio us WordPress Creating a Static Directory Posted by root 1 hour 21 minutes ago (http://i.ndustrio.us) Dec 1 2006 i tried out jack born static jack plugin which is supposed to allow you the ability to post a comment or leave a trackback trackback url technical middot technology middot template middot thanksgiving middot theme middot tips middot troubleshoo Discuss  |  Bury |  News | i ndustrio us WordPress Creating a Static Directory [...]

  2. [...] i ndustrio us WordPress Creating a Static Directory Posted by root 24 minutes ago (http://i.ndustrio.us) From time to time i find myself wanting to drop files into a directory under the root location of wordpress occasionally it nice to upload and link to Discuss  |  Bury |  News | i ndustrio us WordPress Creating a Static Directory [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*