I Made Krisna's Times My Way to Write the Times

31Mar/111

.htaccess URL Rewrite on IIS 7.5

Many web applications distributed with .htaccess file to work properly, especially PHP sites. The problem is coming when the web server that is used cannot read or support the .htaccess operation like url rewrite that is common use of .htaccess files. One of that web server is Microsoft IIS, in this post it will be IIS 7.5.

How to do the .htaccess operation with Microsoft IIS 7.5? There is no way (as i know, please tell me if there is). But there is the equivalent operation with .htaccess file do using web.config on IIS.

First we need the IIS module for importing the .htaccess configuration and convert it to web.config configuration, it's named "URL Rewrite 2.0". The module can be downloaded from Mircosoft IIS official site (http://www.iis.net/download/urlrewrite) choose your windows version x86/x64 or install it automatically using Mircosoft Web Platform Installer.

IIS URL Rewrite 2.0 enables Web administrators to create powerful rules to implement URLs that are easier for users to remember and easier for search engines to find. By using rule templates, rewrite maps, .NET providers, and other functionality integrated into IIS Manager, Web administrators can easily set up rules to define URL rewriting behavior based on HTTP headers, HTTP response or request headers, IIS server variables, and even complex programmatic rules. In addition, Web administrators can perform redirects, send custom responses, or stop HTTP requests based on the logic expressed in the rewrite rules.

URL Rewrite IIS Manager

After installing IIS URL Rewrite module, the configuration can be accessed using the menu which should be already showed in IIS Manager when you choosing one of the IIS site. After choosing the URL Rewrite menu, go to the sidebar and click the "Import Rules..." link.

In the import mod_rewrite Rules window, browse your web site configuration file or .htaccess file which want to be converted or applied to IIS then the next step is just click the "Import" button. The module will do the conversion for you.

For example .htaccess configuration is:

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

Will be converted to:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="/index.php/{R:1}" />
    </rule>
  </rules>
</rewrite>


References:

  1. Ruslan Yakusev, IIS Learning Center, Importing Apache mod_rewrite Rules, http://learn.iis.net/page.aspx/470/importing-apache-modrewrite-rules/ (31 March 2011)
  2. Official Microsoft IIS Site, URL Rewrite, http://www.iis.net/download/urlrewrite (31 March 2011)

Related posts:

  1. Removing ‘index.php’ from CodeIgniter URL
  2. Set Up HTTPS/SSL with Apache2.2 for Windows
  3. Building PHP Webserver on Nginx with PHP CGI
  4. phpMyAdmin + PHP 5.3.x Blank Page Login
  5. Pidgin for Facebook Chat
Comments (1) Trackbacks (0)
  1. You may get my version IIS Rewrite, support .htaccess file’s.
    This page in Russian. Translate this page with Google Translate.
    http://www.lanuser.ru/19.09.2011/new-version-rewrite.xhtml


Leave a comment

(required)

No trackbacks yet.