Getting Extensionless URLs for WordPress on Windows Using ISAPI_Rewrite


Okay, a little bit niche but I couldn’t find any decent info online.

DISCLAIMER: This works for my hosting. Don't blame me if this borks your install. Remember that I'm just some random guy on the internet.

My site is hosted with Blacknight. I originally had the site set up using the built-in Web Applications installer. It’s very easy to get a WordPress site up and running using that but it comes with the caveat that the whole installation can’t be manually written to.

Yes, they block all editing access to the WordPress installation directory. I’m not sure why. But it’s annoying. So, I started off with a fresh install.

Why we’re doing this

WordPress supports extensionless URLs on Windows but it’s in the format yourblog.com/index.php/a-post-title. Which isn’t terrible but isn’t really great either. I’m not keen on the index.php part being stuck on every URL.

In my case, I wanted to get this working because the Origin theme that I use has a minor bug where paging stops working when any custom URLs are switched on (it misses the index.php bit). So, rather than learn some PHP (yuck) I thought I’d give URL rewriing a go.

ISAPI_Rewrite

ISAPI_Rewrite is a powerful URL manipulation engine based on regular expressions. It acts mostly like Apache’s mod_Rewrite, but is designed specifically for Microsoft’s Internet Information Server (IIS).

This is an option within Blacknight’s shared hosting so the first thing I did was enable it.

That creates a bunch of examples and gives a link to documentation about how to use it. Nah, only kidding, it creates a file called ‘ISAPI_Rewrite.config.file.name’ with a few example rules with almost no documentation about how they work.

So, throwing that out, I went and did some digging.

Configuration

This is how my site is set up within the shared hosting:

[root]
  |- wwwroot
  |  |- blog

ISAPI-Rewrite is configured through a .htaccess file that sits in the root of the directory it needs to affect. So, in my case, I want to put it in the blog directory.

I want it to ingore any files that exist on disk and to ignore any folders but rewrite any URL to the same location with a index.php stuck on the end.

So, ~/blog/test-post/ becomes ~/blog/text-post/index.php

This gives me the following rules:

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

Taken line-by-line, we’re:

  1. Switching the rewrite engine on
  2. Settings the base URL for it to monitor to ~/blog (I’ve got other stuff running under this domain and I don’t want them to be affected)
  3. Telling it to ignore any files that exist on disk
  4. Telling it to ignore any directories
  5. Telling it to rewrite any matched path to /blog/index.php and then add the path back on

So, put this into an .htaccess file, copy up to the root of your WordPress installation and that should be you.