htaccess equivalent (Zend Framework with IIS7)

The Zend Framework relies on a web directive to redirect ALL requests to an index.php page. On an apache server, this is fairly easy to implement using the following statements in a .htaccess file in the public facing folder:

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

A new feature in IIS7 called ‘URL Rewrite’ makes this easy to realize on WIMP/WISP setups. The GoLive (Production) version of the plugin is available here:

(X86)http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1691
(X64)http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1692

The plugin provides a really neat feature to directly import and convert well formed .htaccess files into their IIS equivalents. Using your IIS manager, navigate to the virtual folder (pointing to your public facing folder). Click on the ‘URL Rewrite’ plugin and then the "Open Feature" option.

UrlRewrite1

Now, click on the "Import Rules" option

Rewrite_import

In the dialog box that appears, select the .htaccess file saved on your computer and click on the "Import" button.

rewrite_select

If all goes well, the equivalent IIS rewrite rules will be created! The above procedure actually creates a web.config file in your public folder that looks like the following (Note that you can actually just copy this web.config to your folder instead of going through the above steps):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1">
                    <match url="\.(js|ico|gif|jpg|png|css)$" negate="true" ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s