Thursday, May 31, 2012

Translating an Apache .htaccess file to an IIS web.config

I developed an application on my local using PHP, MySQL and Apache and it has a .htaccess file containing this:

#Setting the default handler.

<IfModule mod_mime.c>
#Supporting .do extensions
AddType application/x-httpd-php .do

<IfModule mod_rewrite.c>
#Removing .do file extension if necessary
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.do -f
RewriteRule ^(.*)$ $

But I informed that my customer's web server is IIS and I have to use a web.config file instead of .htaccess. Can anyone direct me through this, please?

Source: Tips4all


  1. This article worth a look:
    Translating .htaccess Content to IIS web.config

  2. This could be seen as cheating, but we use ISAPI_Rewrite, which lets you just use the .htaccess file for IIS. If you can get them to put it on the server, you won't need to translate anything.

  3. Please be aware that this will only work on IIS7 and not on IIS6. Also this requires FastCGI to be setup and the URL Rewriting module to be installed and enabled. These are things your hoster will be able to verify for you. If all of the above is true then the following file should do the trick ( you might need to tweak the paths but again I think your hoster will be able to do this for you if you supply them with this example file.

    <?xml version="1.0" encoding="UTF-8"?>
    <sectionGroup name="system.webServer">
    <sectionGroup name="rewrite">
    <section name="rewriteMaps" overrideModeDefault="Allow" />
    <section name="rules" overrideModeDefault="Allow" />

    <!-- Mapping the .do extension to the PHP ISAPI module -->
    <!-- the following line is very specific to your host
    please check the module name and the scriptProcessor
    path with the system administrator! basically this is
    the same as
    only in .config format. -->
    <add name="MaskDoAsPHP" path=".do" verb="GET,HEAD,POST,DEBUG" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe" />

    <!-- Setting the default handler. -->
    <clear />
    <add value="" />

    <rule name="Removing do extension" stopProcessing="true">
    <match url="^(.*)$" ignoreCase="false" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
    <action type="Rewrite" url="{R1}.do" appendQueryString="true" />