【发布时间】: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