TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
IIS 7/7.5 URL rewrite and Kohana
  • For some God forsaken reason I decided to give IIS a try on my local development machine, although my development stack is actually a private LAN Debian VPS + nginx + php-fpm, so no, please don't start the "don't downgrade to IIS" crap. Debian + the other stuff is still my favorite option for web servers.

    Unfortunately none of the stuff that I could find by digging this forum or Google's cache could help. So here is the checklist:
    » IIS 7 or 7.5 - checked. I am using 7.5 under Windows 7 Professional x64. The IIS 7 scenario is untested, but it should work since I guided myself by reading IIS 7 documentation.
    » Zend Server CE 5.0.0 - checked. It comes with automatic configuration for IIS plus Zend Optimizer+ and Zend Data Cache. The default binary Windows distribution should work as well. Since Zend Server 5.0 is built with VC9, you can also use extensions from the php.net Windows distribution without the "OMG I don't have the msvcr80.dll around" or potential incompatibilities as the old ZS (4.0.x) was built with VC8.
    » IIS URL Rewrite Module - checked. I use the v1.1 since I don't have the mood for testing the v2.0 RC2. http://www.iis.net/expand/URLRewrite

    This was my first experience with IIS, so I started to dig for it's MMC since I know that it has one. Adding another default document (index.php) was pretty straight forward, actually quite idiot proof. Then I saw a fresh web.config file under the web root. That's it, after years of doing things with nano under a *nix shell over SSH, a pretty XML file won't hurt me. So here's my manually pimped config file:

    <?xml version="1.0" encoding="UTF-8"?>
    <add value="index.php" />
    <rule name="Fail bad requests">
    <match url=".*"/>
    <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
    <action type="AbortRequest" />
    <rule name="Kohana" stopProcessing="true">
    <match url="^(.+)$" />
    <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <action type="Rewrite" url="index.php?kohana_uri={R:1}" />

    The defaultDocument node is pretty self explanatory. The rewrite is interesting with its quite simple rules.

    1st rule should drop "bad requests" as using or http://ip.of.the.machine/ instead of the host name. The "localhost" pattern is actually the restriction, thus the server is OK with http://localhost/ but it resets any connection to In production you shouldn't serve anything by using the default virtual host anyway aka the http://ip.of.the.machine/ should be something like a blank page as the security oriented minds would say since it avoids some of the automatic scanners.

    The 2nd rule is actually the Kohana rewrite rule, adapted from my nginx rewrite config. It's pretty self explanatory as well.

    Good luck with IIS.
  • Thanks for this, I was wondering about how Kohana rewrite rules would play with IIS.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion