2013-07-10 55 views
2

我試圖導入.htaccess文件到URL重寫規則在IIS 7導入時出現問題的.htaccess到IIS URL重寫程序Web.Config

中的Symfony 2當前文件失敗將它導入到IIS。我需要知道語法的人的幫助以將文件轉換爲IIS可用的文件,這吸引了這項工作對IIS中Symfony 2的未來用戶的幫助。

我很抱歉不知道IIS中的語法。我附加了原始文件/web/.htaccess,爲方便起見,排除了所有註釋。

在此先感謝

DirectoryIndex app.php 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 

    RewriteRule ^(.*) - [E=BASE:%1] 
    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 

    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 
    RewriteCond %{REQUEST_FILENAME} -f 

    RewriteRule .? - [L] 
    RewriteRule .? %{ENV:BASE}/app.php [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    <IfModule mod_alias.c> 
     RedirectMatch 302 ^/$ /app.php/ 
    </IfModule> 
</IfModule> 

電流誤差輸出是這樣的:

<rewrite> 
    <rules> 
    <!--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'--> 
    <rule name="Imported Rule 3" stopProcessing="true"> 
     <match url=".?" ignoreCase="false" /> 
     <conditions> 
     <!--# If the requested filename exists, simply serve it.--> 
     <!--# We only want to let Apache serve files and not directories.--> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> 
     </conditions> 
     <action type="None" /> 
    </rule> 
    <!--This rule was not converted because it contains references that are not supported: 'ENV::BASE'--> 
    </rules> 
</rewrite> 

在此先感謝

回答

3

如果您從域的根app.php(http://domain.tld/app.php )比你可以刪除ENV:BASE變量。 這將導致以下XML在IIS中導入:

<rewrite> 
    <rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="^app\.php(/(.*)|$)" ignoreCase="false" /> 
     <action type="Redirect" redirectType="Permanent" url="/{R:2}" /> 
    </rule> 
    <rule name="Imported Rule 2" stopProcessing="true"> 
     <match url=".?" ignoreCase="false" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> 
     </conditions> 
     <action type="None" /> 
    </rule> 
    <rule name="Imported Rule 3" stopProcessing="true"> 
     <match url=".?" ignoreCase="false" /> 
     <action type="Rewrite" url="/app.php" /> 
    </rule> 
    </rules> 
</rewrite> 

編輯:從一個子目錄,這應該工作,我相信(子目錄是「富」):

<rewrite> 
    <rules> 
    <rule name="Imported Rule 1" stopProcessing="true"> 
     <match url="^app\.php(/(.*)|$)" ignoreCase="false" /> 
     <action type="Redirect" redirectType="Permanent" url="foo/{R:2}" /> 
    </rule> 
    <rule name="Imported Rule 2" stopProcessing="true"> 
     <match url=".?" ignoreCase="false" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> 
     </conditions> 
     <action type="None" /> 
    </rule> 
    <rule name="Imported Rule 3" stopProcessing="true"> 
     <match url=".?" ignoreCase="false" /> 
     <action type="Rewrite" url="foo/app.php" /> 
    </rule> 
    </rules> 
</rewrite> 

有可能是一個更好方式與變量,但我只使用IIS URL重寫從mod_rewrite進口。所以,我不知道那些:)

+0

,讓說__foo__我怎麼需要格式化規則以這種方式工作 – Rafael

+0

檢查....:D – Rafael