【发布时间】:2016-10-08 06:53:37
【问题描述】:
我一直在 Apache 环境中使用 Rest Api 开发 PHP 应用程序,这需要重写 URL,所以我使用 .htaccess 文件来编写规则,这在 Apache 中运行良好。
现在,我想在 IIS 环境中使用与 Rest Api 相同的 Php 应用程序,发现 .htaccess 在 IIS 中不起作用,因为它使用不同的语法或方法在 web.config 中编写相同的规则。
在 IIS 环境中转换给定规则时需要帮助。
以下是在 apache 环境中运行良好的规则,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?x=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
web.config(使用 .htaccess 的在线转换器):
<rule name="rule 1q" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<action type="Rewrite" url="/api.php?x={R:1}" appendQueryString="true" />
</rule>
<rule name="rule 2q" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<action type="Rewrite" url="/api.php" appendQueryString="true" />
</rule>
<rule name="rule 3q" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<action type="Rewrite" url="/api.php" appendQueryString="true" />
</rule>
<rule name="rule 4q" stopProcessing="true">
<match url="^" />
<action type="Rewrite" url="/index.php" appendQueryString="true" />
</rule>
【问题讨论】:
-
@yosefh,谢谢。 IIS 具有 URL 重写功能。我确实将我的 .htaccess 文件转换为 web.config。但 IIS 通过错误如下“配置文件格式不正确的 XML”。
-
在问题中包含您的 XML
-
-
余额代码:
标签: php apache .htaccess mod-rewrite iis