2015-05-15 185 views
4

我正在部署使用APIGILITY开发到IIS的API。由于IIS不支持.htaccess我试图从.htaccess文件的内容中创建web.config文件。我使用IISv7.5并试图安装URL重写器来转换规则。但是我在转换时遇到错误。请在.htaccess文件下面找到我从urlRewriter获得的相应转换。htaccess规则(mod_rewrite)转换为web.config规则

.htaccess文件

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
RewriteRule ^(.*) - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

转换的规则和错误,我得到的。

<rewrite> 
    <rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="^.*$" /> 
     <conditions logicalGrouping="MatchAny"> 
     <!--The condition pattern is not supported: -s.--> 
     <!--The condition pattern is not supported: -l.--> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> 
     </conditions> 
     <action type="None" /> 
    </rule> 
    <!--The rule cannot be converted into an equivalent IIS format because of unsupported flags: E--> 
    <!--This rule was not converted because it contains references that are not supported: 'ENV::BASE'--> 
    </rules> 
</rewrite> 

我可以得到一些帮助吗?

+2

我不认为你仍然需要一个基地排序的发现者在你的规则。实际上,如果你有一个规则来内部重写每个文件/文件夹(除了现有的文件)到根目录'index.php',那么它是否正确? –

+1

index.php是否使用这个环境变量?或者这只是一个非常复杂的方式来重写每个请求到这个目录中的index.php文件? – Sumurai8

+0

你有解决这个问题吗?我有同样的问题。 –

回答

1

我找到了解决办法here

基本上,安装IIS URL Rewrite extension,然后创建apigility的根web.config文件与此内容:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <directoryBrowse enabled="false" /> 
     <httpErrors existingResponse="PassThrough" /> 
     <rewrite> 
      <rules> 
      <clear /> 
      <!-- Rewrite rules to /public by @maartenballiauw *tnx* --> 
      <rule name="TransferToPublic-StaticContent" patternSyntax="Wildcard" stopProcessing="true"> 
       <match url="*" /> 
       <conditions logicalGrouping="MatchAny"> 
       <add input="{REQUEST_URI}" pattern="*assets*" /> 
       <add input="{REQUEST_URI}" pattern="robots.txt" /> 
       </conditions> 
       <action type="Rewrite" url="public/{R:0}" /> 
      </rule> 
      <rule name="TransferToPublic" patternSyntax="Wildcard"> 
       <match url="*" /> 
       <action type="Rewrite" url="public/index.php" /> 
      </rule> 
      </rules> 
     </rewrite> 
     <defaultDocument> 
      <files> 
       <clear /> 
       <add value="index.php" /> 
       <add value="index.html" /> 
      </files> 
     </defaultDocument> 
    </system.webServer> 
</configuration>