将.htaccess文件转换为Web.config

时间:2016-08-29 10:42:07

标签: apache .htaccess iis web-config

我正在将我的Web应用程序从Apache 2.4.17迁移到Microsoft-IIS / 7.5。在我的应用程序的根目录是.htaccess文件,需要转换为Web.config。

经过多次尝试后,我无法成功转换。 Microsoft-IIS不断返回404 - 找不到文件错误。我没有编写Web.config文件的经验,因此非常感谢来自更有经验的人的任何帮助。

这是.htaccess文件,它在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]

这是我尝试编写Web.config文件:

<?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>

1 个答案:

答案 0 :(得分:0)

看起来您已经提到过this条。

您能否确认是否已安装网址重写模块:http://www.iis.net/downloads/microsoft/url-rewrite

我建议您启用失败请求跟踪,以了解请求发生了什么以及它们失败的原因。看到这篇文章: http://www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis-85