Home » Book Tech

Working Permalinks With WordPress In It’s Own Directory

14 February 2007 No Comment

I spent half the morning yesterday trying to get this to work. Now that I have, I thought it’d be a good idea to document it here. Not only might I need this again later, but it might be useful to someone else.

My Objective:

I had a two part purpose here. I wanted to be sure my mod_rewrite permalinks functioned correctly, as well as having the root of my website(www.waitingforfairies.com) redirect to the WordPress subdirectory.

My Process:

First, I tried putting WordPress in it’s own directory. This didn’t work for me. Mostly because of the problem and solution for GoDaddy hosting found here, which I’ll get to explaining later.**

To cut a long story short, here’s what I did:

Part 1: Setting Permalinks In WordPress

  1. I moved WordPress completely into it’s own directory. It’s now physically located at http://www.waitingforfairies.com/blog.
  2. I set my permalinks to what I wanted via the WordPress administration panel. In my case, I used the date and name based option: /%year%/%monthnum%/%day%/%postname%/
  3. There is now an .htaccess file in that WordPress directory with the following code:

# BEGIN WordPress

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

# END WordPress

This part is pretty standard, and you can find it in a hundred places if you look.

That resolves part 1 of my objective: to make sure the permalinks work the way I want them to. Now, for part 2: powering the root of this website with WordPress.

Powering The Root With WordPress

  1. I created an .htaccess file in the root directory of my blog.
  2. It’s powered by the following code:

# Turn on rewrites.
RewriteEngine on# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?waitingforfairies.com$# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/blog/# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /blog/$1# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?waitingforfairies.com$
RewriteRule ^(/)?$ blog/index.php [L]

This code effectively reroutes anyone who visits the root of my website directly to my WordPress blog. Voila: Working WordPress permalinks AND WordPress functioning as the root of the site from within it’s own directory.

If you use this method, you’ll need to replace each instance of waitingforfairies.com with your domain. You’ll also need to replace each /blog/ with the name of the subdirectory where you’ve installed WordPress.

And that’s it. Except for one thing…

**Part Three: GoDaddy Hosting and .htaccess

The above referenced article was a sanity saver for me. The reason why I’d spent half the day on this is that I hadn’t realized this about GoDaddy:

NOTE: Changes made to an existing htaccess file will be seen immediately. When a new htaccess file is created or an existing htaccess file is deleted, however, these changes will not be seen until the htaccess cache is cleared. This occurs every hour.

Once I knew this little piece of trivia, the rest became easy. I realize that my method is only one of many. I further realize that anyone with experience will be able to write this code themselves. But that’s what’s great about WordPress. You don’t have to be a guru to do cool things with your website. And if you do happen to be a guru, you can still do cool things with your website without having to reinvent the wheel. So I hope having this information all in one place will benefit someone, somewhere, somehow. Giving back is a good feeling.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.