简体   繁体   English

将.htaccess文件转换为Web.config

[英]Convering .htaccess file to Web.config

I am migrating my web application from Apache 2.4.17 to Microsoft-IIS/7.5. 我正在将Web应用程序从Apache 2.4.17迁移到Microsoft-IIS / 7.5。 In root of my application is .htaccess file which needs to be converted to Web.config. 我的应用程序的根目录是.htaccess文件,该文件需要转换为Web.config。

After numerous attempts i am not able to do a successful conversion. 经过无数次尝试,我无法成功进行转换。 Microsoft-IIS keeps returning 404 - file not found error. Microsoft-IIS不断返回404-找不到文件错误。 I have no experience in writing Web.config files so any help from a more experienced eye would be much appreciated. 我没有编写Web.config文件的经验,因此,经验丰富的人士的任何帮助将不胜感激。

Here is .htaccess file which is working fine on Apache: 这是.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]

And here is my attempt on writing Web.config file: 这是我尝试编写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>

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 您能否确认是否已安装URL重写模块: 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 请参阅本文: http : //www.iis.net/learn/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis-85

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM