How to convert .htaccess to web.config

This post describes some of the IIS URL Rewrite equivalents of commonly used Apache/.htaccess settings. You may find this useful when you want to convert .htaccess to web.config for IIS 7.5 and 8.0 web.config. The second part of this series outlines how to use Internet Information Services (IIS) 7.0 Manager to import and convert a .htaccess file to web.config. You might also be interested in some .htaccess examples for IIS.


Learn how to use .htaccess files in IIS.

This post is divided into multiple pages for ease.

Convert Apache .htaccess to IIS web.config

IIS 7.5 / 8.0 web.config equivalents for Apache’s .htaccess (modules like mod_dir, mod_headers, mod_mime mod_rewrite and mod_gzip). Most Apache .htaccess modules are supported in the IIS URL Rewrite module or as web.config directive.

You just need to know where to find the correct IIS equivalent for Apache .htaccess, follow the next pages to find out…

Apache mod_dir to IIS web.config

http://httpd.apache.org/docs/2.2/mod/mod_dir.html
Provides for “trailing slash” redirects and serving directory index files

IIS web.config: trailing directory slash

IIS web.config: default document -or directory index- files and their order

list of resources to look for when the client requests a directory

IIS web.config: enable and disable directory browsing

Apache mod_headers

http://httpd.apache.org/docs/2.2/mod/mod_headers.html
Customization of HTTP request and response headers

IIS web.config: some example response headers

Apache mod_mime

http://httpd.apache.org/docs/2.2/mod/mod_mime.html
Associates the requested filename’s extensions with the file’s behavior (handlers and filters) and content (mime-type, language, character set and encoding)

IIS web.config: set MIME-type and charset for file extensions

Apache mod_rewrite

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
Provides a rule-based rewriting engine to rewrite requested URLs on the fly

IIS web.config: equivalent (most commenly used variant)

Apache mod_deflate

http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
Compress content before it is delivered to the client

IIS web.config: gzip compression (not deflate), for both static and dynamic file types

Compression with gzip is mostly configured at the webserver level

Freebies, web.config examples

You can configure a lot of other neat stuff in your IIS web.config file. Three (3) examples.

IIS web.config: Set Expire headers to 30 days for static content – freebie #1

IIS web.config: remove/disable unused handlers – freebie #2

IIS web.config: remove/disable unused modules, or add them – freebie #3

IIS 7.0 Manager import

Import .htaccess file with Internet Information Services (IIS) 7.0 Manager and convert to web.config

In the second part of this post series you can learn how to use Internet Information Services (IIS) 7.0 Manager to import and convert a .htaccess file to web.config:

.htaccess in Windows/IIS

Perhaps you don’t want to convert .htaccess to web.config, but want to use .htaccess on IIS web servers?

IIS Outbound Rewrite Rules

IIS also supports so called Outbound Rules. An Outbound Rule is applied to the output stream, from the web server to the client. This makes it possible to rewrite response statuses, HTTP content, and so on. For more information on IIS Outbound Rules, see: