将 .htaccess 文件转换为 Web.config
Convering .htaccess file to Web.config
我正在将我的 Web 应用程序从 Apache 2.4.17 迁移到 Microsoft-IIS/7.5。在我的应用程序的根目录中是 .htaccess 文件,需要将其转换为 Web.config。
经过多次尝试,我无法成功转换。 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= [L]
RewriteRule ^([A-Za-z/]+)/(page=[0-9]+)$ framework/Router.php? [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>
您似乎已经参考了 this 篇文章。
能否确认一下是否安装了URL重写模块: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
我正在将我的 Web 应用程序从 Apache 2.4.17 迁移到 Microsoft-IIS/7.5。在我的应用程序的根目录中是 .htaccess 文件,需要将其转换为 Web.config。
经过多次尝试,我无法成功转换。 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= [L]
RewriteRule ^([A-Za-z/]+)/(page=[0-9]+)$ framework/Router.php? [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>
您似乎已经参考了 this 篇文章。
能否确认一下是否安装了URL重写模块: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