【问题标题】:Convering .htaccess file to Web.config将 .htaccess 文件转换为 Web.config
【发布时间】:2017-01-05 08:50:51
【问题描述】:

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

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

这是在 Apache 上运行良好的 .htaccess 文件:

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>

【问题讨论】:

    标签: apache .htaccess iis web-config


    【解决方案1】:

    看来您已经参考了this 文章。

    能否确认您是否安装了 URL Rewrite 模块: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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多