我有一個重寫規則,它使用子域的值更改服務器變量。 這部作品subdomain.mydomain.nl/somethinghere但不能在subdomain.mydomain.nl在IIS 7.5中重寫服務器變量
<rule name="Change code" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{SERVER_NAME}" pattern="(www\.)?(\w+)\.mydomain\.nl" />
<add input="{SERVER_NAME}" pattern="^www.mydomain.nl.*" negate="true" />
<add input="{SERVER_NAME}" pattern="^mydomain.nl.*" negate="true" />
</conditions>
<serverVariables>
<set name="MYVARIABLE" value="{C:2}" />
</serverVariables>
<action type="None" />
</rule>
我已經測試了2個網址: 1:subdomain.mydomain.nl/somethinghere 2:subdomain.mydomain.nl
我檢索PHP可變用下面的代碼:
echo $_SERVER['MYVARIABLE'];
在URL 1的情況下,這樣做的輸出被「子域」。
在URL 2的情況下,這樣做的輸出爲「」。
URL 1的輸出是正確的,但URL 2的輸出應該是「子域」了。
我已經運行兩個請求的痕跡,他們都表明,規則被匹配和執行。
任何人都可以幫助我嗎?
非常感謝您的回答,這就是解決方案。真奇怪,我無法找到任何記錄。 – user1071188
要設置請求標頭,需要添加HTTP_。這是記錄[這裏](http://learn.iis.net/page.aspx/665/url-rewrite-module-20-configuration-reference/#Setting_Server_Variables)(請參閱「關於請求標題的注意事項」)。然而,我也困惑的是爲什麼設置請求標題總是有效,但設置服務器變量似乎並不總能奏效。 –
謝謝你。你救了我的命! –