Pretty Permalinks, WordPress, and EasyCGI

As it turns out, not many folks are using WordPress on an EasyCGI hosted IIS server, so getting “pretty permalinks” to work properly was a bit tricky. Combine that with the fact that I know very little about this stuff, and things got a bit interesting. However, after a bit of research, patience, and tech support, I finally got it all working.

First of all, EasyCGI’s Windows-hosted IIS servers do not support the mod_rewrite method that most folks use for permalinks. (I figured that out pretty quickly.) I then tried this fix, but I had no luck with it.

I finally ended up using the custom 404 page method described here, here, and here. Those sites all link back to one other, so I’m not sure which one originally cracked the code, but I’m glad they did!

Specifically, I ended up creating a custom wp-404-handler.php file and placed it in my root directory. Within it I inserted the following code:

$pos = strrpos($qs, '://');
$pos = strpos($qs, '/', $pos + 4);
$_SERVER['REQUEST_URI'] = substr($qs, $pos);

I then accessed my IIS Admin Console (via EasyCGI’s control panel), and I configured the custom 404 error page for the “/wordpress” directory (my chosen installation directory for WordPress) to point to “/wp-404-handler.php”. I originally tried creating the custom 404 file in the “/wordpress” directory, but after some trial and error, I found that it only works when placed in the root directory.

For what it’s worth, I also tried the updated and longer version of code found here, and I can confirm that it works, too. However, I decided to stick with the shorter version because (1) it works and (2) it has less code. While it may not be as “robust” as the longer code solution, my thoughts are that it may be more efficient in the long run. Maybe I’m wrong?

Throughout the process, I contacted EasyCGI’s 24×7 live chat support, and they responded immediately and were very quick to assist. Their original solution was to place the following code into an httpd.ini file, which is the same code that would go into an .htaccess file when using the “usual” mod_rewrite method (that IIS doesn’t support):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

However, that didn’t work for me, so they created a support ticket and one of their higher-level techs got involved. His original solution was to just settle with the “almost pretty permalinks” (which includes index.php in the URL), but I told him about the custom 404 page method. He looked into it and helped me get all of the code in the proper place. Overall, I am very pleased with EasyCGI’s tech support!

The only quirk with the custom 404 page fix is that invalid URLs now land on a blank page. I’m not sure how to fix this (or if it’s really a problem). In the end, I’m mainly glad that I got pretty permalinks to work.  :)


  • Colby Hearn

    Awesome work, man.
    Like I said, a short hop and here you are! lol
    I vote you blog occasionally about Android development.