Support » Fixing WordPress » IIS URL Rewrite Rules?

  • I installed WordPress 1.2.1 on my hosting provider. PHP 4.3.4 is installed as well as mySQL (don’t know the version off the top of my head). However they run on IIS 🙁 Yeah I know about IIS sucking and Apache being better. Looking at moving to another host but that doesn’t help me right now.
    I’m trying to get permalinks working and needing to get URL rewriting on the server. I enabled permalinks in the WordPress admin section with the following settings:
    I was then told to use these rules for URL rewriting:
    RewriteEngine On
    RewriteBase /
    RewriteRule ^archives/category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2 [QSA]
    RewriteRule ^archives/category/?(.*) /index.php?category_name=$1 [QSA]
    RewriteRule ^archives/author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2 [QSA]
    RewriteRule ^archives/author/?(.*) /index.php?author_name=$1 [QSA]
    RewriteRule ^archives/([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([_0-9a-z-]+)?/?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5 [QSA]
    RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([_0-9a-z-]+)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5 [QSA]
    RewriteRule ^archives/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([_0-9a-z-]+)/trackback/?$ /wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4 [QSA]
    RewriteRule ^feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1 [QSA]
    RewriteRule ^comments/feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1&withcomments=1 [QSA]

    I gave this to my hosting provider and they included it but it’s not working.
    Here are my questions:
    1) Does the rewrite rules that WordPress displays, specific to Apache or do they take into consideration which web server I’m running?
    2) If it defaults with only Apache rewrite rules then is there anything I need to alter in the above rewrite rules to make it work with IIS and a windows machine?
    Thanks in advanced for any help with this.

Viewing 13 replies - 1 through 13 (of 13 total)
  • No, mod_rewrite is not something IIS knows about, at least not without help (and even then not completely). If you want to use custom permalinks on your site, you’ll have to pass them through index.php, like so:
    This WordPress will (almost always) work with without aid from the server.

    Yeah I tried this and it gives me an error. (tries to find the directory: index.php\blah\year\, etc)
    I guess I’m just confused if the rewrite rules I’m being told to enter (by WordPress), are really those that I need to have my ISP enter for IIS. Does anyone know or have any experience with rewrite rules on IIS? Are those above or the new ones below need to be tweaked to work on ISS?
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php/archives/category/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?category_name=$1&feed=$2 [QSA]
    RewriteRule ^index.php/archives/category/?(.*) /index.php?category_name=$1 [QSA]
    RewriteRule ^index.php/archives/author/(.*)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?author_name=$1&feed=$2 [QSA]
    RewriteRule ^index.php/archives/author/?(.*) /index.php?author_name=$1 [QSA]
    RewriteRule ^index.php/archives/?([0-9]{4})?/?([0-9]{1,2})?/?([0-9]{1,2})?/?([_0-9a-z-]+)?/?([0-9]+)?/?$ /index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5 [QSA]
    RewriteRule ^index.php/archives/?([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([_0-9a-z-]+)/(feed|rdf|rss|rss2|atom)/?$ /wp-feed.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5 [QSA]
    RewriteRule ^index.php/archives/?([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([_0-9a-z-]+)/trackback/?$ /wp-trackback.php?year=$1&monthnum=$2&day=$3&name=$4 [QSA]
    RewriteRule ^feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1 [QSA]
    RewriteRule ^comments/feed/?([_0-9a-z-]+)?/?$ /wp-feed.php?feed=$1&withcomments=1 [QSA]

    After thinking about this, there actually does seem to be a good solution. A custom 404 page in IIS.
    By setting “/index.php” as the 404 error page (in “URL” mode, not “FILE”), a bit of script in the index file could perform the necessary functions by assigning the internal variables based on the querystring var IIS will pass (called “404” I think”) to it.
    Someone with more PHP skill than I would be able to whip up an INCLUDE to do the parsing if the web server doesn’t have a mod_rewrite (or equivalent) installed. That script could even read an “htaccess” file and transparently use the exact same format that mod_rewrite does.

    Further to that, after a little testing with ASP (still learning PHP), using “index.php” as a custom 404 page should work perfectly. The browser will see the “pretty” URL (as will search engines), and because the 404 is handled internally by the server (at least in IIS), the browser (or search engine) will get a normal 200 OK header, not a 404 header. Perfect!
    And after looking a bit at the WordPress Plugin API and a little peering into the wp-header.php file, it looks like this functionality *might* work as a plugin.
    I don’t currently have the PHP skill necessary to work with regular expressions such as the ones mod_rewrite uses (which would be ideal – easiest for the user since the rules are given on the Permalink Options page), but I think it’s possible to implement this as a plugin. I’ll do some more checking, but in the end, someone else will probably have to write it.

    That is a pretty good idea. I’m also just starting to learn PHP as well as the WordPress API. I’m hoping someone will have already done this or perhaps be willing to help out. I would imagine it wouldn’t be that hard. Maybe I’ll give it a try and hack out some code.
    Another thought, what would happen if someone clicked on a link and really did get a 404 error. Would the above mentioned script be able to handle that case? I’m thinking it would as long as it used the rewrite expressions.
    Anyways, if someone has got some experience and/or the desire to work on this, I’d be glad to help…let me know.

    Presumably, whatever script was added to the “index.php” page (or as a plug-in – as long as it executed before any data was actually echoed to the browser) would know if a given URL was actually valid or not. If someone should receive an actual 404 page, it’s simple enough to return a 404 header with PHP (and ASP for that matter), but if the article/entry exists, they see the content normally (getting the 200 OK message).

    I wouldn’t suggest setting your 404 page to be index.php. I’ts just not the correct way to solve the problem. Instead, I would suggest installing ISAPI Rewrite Lite from and installing your rewrite there. This more nearly approximates the .htacces that is associated with apache. I have links to some excellent information on my site at
    Feel free to drop me a note if your still having troubles.

    But it’s not free, and not built-in. Many hosts have no problem setting custom 404 pages, but most will not want to install external components onto their servers.
    I’ve tried the method now with ASP and it works beautifully. The browser gets a 200 OK message from the page (as would a search engine), and people never need to see ugly URLs again 🙂
    The ideal method, of course, is just to use Apache…

    ISAPI Rewrite Lite from Helicon IS FREE! and it works just fine for me. I still have the option of creating a custom 404 page… When I get around to it. This way when a crawler finds a non-existant page, they won’t tend to catoragize it as my home page…. Unless, of course that’s what your looking for.

    The Lite version does server-wide changes *only*, it cannot (will not, rather) work for a single virtual host. The non-free version will work on a per-folder basis and per-server basis, just like the Apache mod_rewrite. The free version isn’t particularly useful if different people want different rewrite rules for their blogs. I’ll reiterate that most virtual host providers will *not* install 3rd party controls on their IIS servers, making it completely useless regardless of which version you use.
    There’s no reason the “index.php” can’t show an actual error page if the article doesn’t exist. If a story doesn’t show up in the database, it’ll return a 404 header with explanatory code. If the story does appear, it’ll return a 200 header and show it. Honestly, the PHP code to do this isn’t particularly advanced, but I don’t know the WP code well enough to know if it’s a viable option. Yet.

    Hello Guys can someone look at this post and suggest something it relates to the same topic

    Hi Guys,

    I programmed a Mod Rewrite filter for IIS. It’s free and open source! Give it a try and if you like it, help me spread the word…

    URL Rewrite for IIS


    I just came up with a work-around for using permalinks in IIS without using any ISAPI URL Rewrites. (Although the one above works nicely.)

    The solution uses custom 404 redirects to accomplish the same end. The best thing? You don’t have to learn any regular expressions!

    Here’s the link to the solution:

    Permalinks without URL Rewrite

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘IIS URL Rewrite Rules?’ is closed to new replies.