Deviant Logo

Rewriting URLs with Apache

post details top
Oct 14th, 2007
post details top

As some of you have probably noticed I use WordPress to manage this site.

Which is great, I like it, and my friend Jordan (hyper123.net) has a system that automatically updates it for me. Sweet. All is well, right?

Well… it was until today. The problem is that WordPress works, and makes URLs “pretty” by rewriting them (which it does by putting a .htaccess file in your root install directory).

So what’s the problem you ask? Well.. at least with DreamHost, this broke something I tried to setup today.

I tried to make a folder for a friend, lets call him “Bob.” So naturally I named the folder “bob,” right? So I make the folder and go to it in my browser (something like http://woodruffrc.com/bob). All is well. Now here is the tricky part: I wanted Bob’s folder to be password protected. Ok, no problem, right? Wrong. I login to my DreamHost panel, and setup the password protection / WebDAV. About 10 minutes later I get an email saying that the process is complete. Yay, I go check it. Nothing. It redirects me to http://woodruffrc.com, the blog. hmmm.. I’m confused.

But I remember seeing something about DreamHost changing the permissions on your directory if you enable WebDAV. Maybe that has something to do with it? I’m still not sure if that’s exactly the problem, but I assume it is.

WordPress uses a statement like this:

RewriteEngine On ["Turn rewriting on."]

RewriteCond %{REQUEST_FILENAME} !-f ["Is it a real file?"]
RewriteCond %{REQUEST_FILENAME} !-d ["Is it a real directory?"]
RewriteRule . /index.php [L] ["No? Redirect it to the blog!"]

To rewrite it’s URLs. I’m guessing that when it changed the owner of the directory, this statement was no longer able to tell if what I was requesting (http://woodruffrc.com/bob) was a real directory. So it assumed it wasn’t, and redirects it to the blog.

Here is the fix:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(stats/|bob/|missing\.html|failed_auth\.html) [NC]
RewriteRule . – [L]

[Wordpress already had all this]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

The above section I found on the DreamHost Wiki to prevent WordPress from breaking your ability to view your stats (http://woodruffrc.com/stats). I just modified it, and included my friend’s directory. :)

Leave a Reply