views:

1726

answers:

3

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

#Setting the default handler.
  DirectoryIndex home.do

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

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

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?

+4  A: 

This article worth a look, I think.
Translating .htaccess Content to IIS web.config

Sepehr Lajevardi
thank you Sepehr, but I can't get it to work. can you show the final web.config code?
Stephanie Luther
Sorry Stephanie, I'm a LAMP guy, I think. since your question has been visited only for 15 times, you might want to try a bounty. cheers ;)
Sepehr Lajevardi
+3  A: 

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"?>
<configuration>
    <configSections>
        <sectionGroup name="system.webServer">
            <sectionGroup name="rewrite">
                <section name="rewriteMaps" overrideModeDefault="Allow" />
                <section name="rules" overrideModeDefault="Allow" />
        </sectionGroup>
    </sectionGroup>
</configSections>

<system.webServer>
    <!-- Mapping the .do extension to the PHP ISAPI module -->
    <handlers>
        <!-- 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
             http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/#EnableFastCGI
             only in .config format. -->
        <add name="MaskDoAsPHP" path=".do" verb="GET,HEAD,POST,DEBUG" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe" />
    </handlers>

    <!-- Setting the default handler. -->
    <defaultDocument>
        <files>
            <clear />
            <add value="home.do" />
        </files>
    </defaultDocument>

    <rewrite>
        <rules>
            <rule name="Removing do extension" 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="{R1}.do" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

olle
thanks olle and im sorry for the late reply! I'm done finally, your code helped :D
Stephanie Luther
Ok good, if you let me know what was "wrong" with it I can update the awnser for future visitors.
olle
+4  A: 

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.

ojrac