0

I am migrating my web application from Apache 2.4.17 to Microsoft-IIS/7.5. In root of my application is .htaccess file which needs to be converted to Web.config.

After numerous attempts i am not able to do a successful conversion. Microsoft-IIS keeps returning 404 - file not found error. I have no experience in writing Web.config files so any help from a more experienced eye would be much appreciated.

Here is .htaccess file which is working fine on Apache:

php_value post_max_size 70M

RewriteEngine on

# In case router is called do nothing
RewriteRule ^framework/Router.php(.)*$ - [L]

# Prevents user from making a request to a specific .php file
RewriteRule ^[A-Za-z/]+.php$ - [F,L]

# Application index page
RewriteRule ^$ domov [L]

# Redirect everything else to Router.php
RewriteRule ^[A-Za-z/]+$ framework/Router.php [L]

RewriteRule ^([A-Za-z/]+)([0-9]+)$ framework/Router.php?id=$2 [L]
RewriteRule ^([A-Za-z/]+)/(page=[0-9]+)$ framework/Router.php?$2 [L]

And here is my attempt on writing Web.config file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="rule 1G" stopProcessing="true">
                <match url="^framework/Router.php(.)*$"/>
                <action type="Rewrite" url="/-" />
            </rule>
            <rule name="rule 2G" stopProcessing="true">
                <match url="^[A-Za-z/]+.php$"  />
                <action type="Rewrite" url="/-"/>
            </rule>
            <rule name="rule 3G" stopProcessing="true">
                <match url="^$"  />
                <action type="Rewrite" url="/domov"/>
            </rule>
            <rule name="rule 4G" stopProcessing="true">
                <match url="^[A-Za-z/]+$"  />
                <action type="Rewrite" url="/framework/Router.php"/>
            </rule>
            <rule name="rule 5G" stopProcessing="true">
                <match url="^([A-Za-z/]+)([0-9]+)$"  />
                <action type="Rewrite" url="/framework/Router.php?id={R:2}" appendQueryString="true" />
            </rule>
            <rule name="rule 6G" stopProcessing="true">
                <match url="^([A-Za-z/]+)/(page=[0-9]+)$"  />
                <action type="Rewrite" url="/framework/Router.php?{R:2}" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>
hardidoo
  • 3
  • 4

1 Answers1

0

Looks like you have already referred this article.

Could you confirm if you have installed URL Rewrite module: http://www.iis.net/downloads/microsoft/url-rewrite

I will recommend you to enable Failed Request Tracing to understand what is happening with the requests and why they are failing. See this article: http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis-85

Kaushal Kumar Panday
  • 2,329
  • 13
  • 22
  • Thank you, i followed your answer and now its working fine. Just as a side note, if you don't have IIS Manager installed it is covered in this question: http://stackoverflow.com/questions/30901434/iis-manager-in-windows-10 – hardidoo Aug 29 '16 at 19:39