apache icon
18th
May 09

URI Rewriting Alongside WordPress’ PermaLinks

Posted Monday 18th May 2009
With the release of this Journal I decided to use WordPress’ permalinks, which basically provides an easy hassle-free option for rewriting WordPress’ URI’s. When uploading my most recent site there was a conflict with .htaccess and my rewrites simply weren’t working.

For the sake of simplicity and logic I decided to follow the WordPress format but still stumbled across some problems. After some rookie errors I thought I would share this as it was one of those things I just kept missing!

Getting Along

Below is what WordPress wrote to the .htaccess file.

1
2
3
4
5
6
7
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /journal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /journal/index.php [L]
</IfModule>

To add our own rewrites we need to rewrite the base path again. If the base directory is the public root directory (like http://www.example.net/) simply add a forward slash.

1
RewriteBase /

This is where I tripped up. After setting your rewrite conditions and then making a rewrite rule you must provide the absolute path from the public root directory. So don’t miss that forward slash!

1
RewriteRule ^(.*)\.html$ /index.php?gibbs=$1 [L]

And finally a simple rewrite would look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /index.php?gibbs=$1 [L]
 
RewriteBase /journal/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /journal/index.php [L]
</IfModule>

Bookmark or share this page:

SociBook del.icio.us Digg Facebook Google Yahoo Buzz StumbleUpon

MSN Contact: contact [at] danielgibbs.net



3 Comments

  1. Kelly Brown 13 June 2009 3:45 am

    The article is ver good. Write please more

  2. Luis F. 30 August 2009 6:02 am

    Nice write up…usually I never reply to these thing but this time I will,Thanks for the great info

  3. Cath Kidston Bedding 13 October 2009 4:00 pm

    I just ran into this, had 3 new blogs on the go that had url rewriter at the top level.

    Thanks

TrackBack URL

Leave a comment