我一直在Apache环境中使用Rest API处理Php应用程序,这需要重写URL,所以我使用了.htaccess文件来编写规则,这在Apache中运行良好。从Apache(.htaccess)到IIS的URL重写问题
现在,我想在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>
看看http://stackoverflow.com/questions/10399932/setting-up-redirect-in-web-config-file,http://www.iis.net/downloads/microsoft/url-rewrite和http://www.htaccesstowebconfig.com/ – yosefrow
@ yosefh,谢谢。 IIS具有URL重写。我确实将我的.htaccess文件转换为web.config。但IIS通过错误如下“配置文件格式不正确的XML”。 –
在问题 – yosefrow