2015-10-05 142 views
1

因此,我無法將IIS中的此重寫規則轉換爲Apache。在IIS中工作良好,但在Apache中完全沒有。將IIS重寫規則轉換爲Apache

原始IIS重寫規則:

<rule 
enabled="true" 
stopProcessing="true" 
name="Route API calls to test server」> 
 <match url="(api/.*)" /> 
 <action type="Rewrite" url="http://api.testdomain.com/{R:1}" /> 
</rule> 
我正在嘗試

阿帕奇規則:

RewriteEngine on 
RewriteRule ^api/(.*)$ http://api.testdomain.com/$1 [P] 
+0

你想代理這個請求,或者只是重定向/重寫到新的網址是什麼? –

+0

代理。想想我已經想通了。在下面回答。 –

回答

0

所以看起來我並沒有履行在攜帶原有規則的原始莢'/ api'與請求。下面的修改規則現在就像一個魅力(儘管我已經硬編碼了路徑的'/ api'部分,但結果相同)。

原始IIS重寫規則:

<rule 
    enabled="true" 
    stopProcessing="true" 
    name="Route API calls to test server」> 
    <match url="(api/.*)" /> 
    <action type="Rewrite" url="http://api.testdomain.com/{R:1}" /> 
    </rule> 

阿帕奇規則

RewriteEngine on 
    RewriteRule ^/api/(.*)$ http://api.testdomain.com/api/$1 [P]