2015-05-15 230 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>