<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Rewrite" stopProcessing="true"> <match url="(.*)" ignoreCase="true" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php" /> </rule> <rule name="Rewrite" stopProcessing="true"> ... </rule> </rules> </rewrite> </system.webServer> </configuration>
濡傛灉瑕佹坊鍔犲涓鏍硷紝鍙渶瑕佹坊鍔 <rule>...</rule> 瀵瑰氨鍙互浜
<match> 鏍囩涓鸿鍒欐ā寮忥紝鐢ㄤ簬鍖归厤 URL 瀛楃涓茬殑姝e垯琛ㄨ揪寮忔垨閫氶厤绗︺
<conditions> 鍙夋潯浠舵ā寮忥紝濡傞獙璇佽姹傜殑 URL 鏄惁瀵瑰簲浜庣墿鐞嗘枃浠剁郴缁熶笂鐨勬枃浠舵垨鐩綍銆
濡傛灉杩欎袱鑰呮ā寮忎换涓涓笉婊¤冻锛孶RL 閲嶅啓妯″潡灏嗙珛鍗冲仠姝㈠鐞嗚瑙勫垯锛屽苟鎵ц涓嬩竴涓鍒欙紝濡傛灉閮藉尮閰嶏紝灏辨墽琛 <action> 鍔ㄤ綔锛屽鏋滆缃 stopProcessing="true"锛岀▼搴忓氨浼氳缁堟锛屼笉鍐嶅線涓嬬户缁簡锛屼负 false 浼氱户缁墽琛屼笅涓瑙勫垯锛宻topProcessing 榛樿鍊间负 false銆
璇锋眰鐨 URL 濡備綍涓庤鍒欐ā寮忓尮閰嶅憿锛
HTTP URL 璇锋眰瀛楃涓叉牸寮忥細http(s)://<host>:<port>/<path>?<querystring>
<host> 杞崲涓 HTTP_HOST 鏈嶅姟鍣ㄥ彉閲忥紝鍦 <conditions> 鏉′欢妯″紡涓闂
<port> 杞崲涓 SERVER_PORT 鏈嶅姟鍣ㄥ彉閲忥紝鍦 <conditions> 鏉′欢妯″紡涓闂
<path> 閮ㄥ垎涓 <match> 瑙勫垯妯″紡鐨 rul 灞炴ф鍒欒〃杈惧紡杩涜鍖归厤
<querystring> 杞崲涓 QUERY_STRING 鏈嶅姟鍣ㄥ彉閲忥紝鍦 鏉′欢妯″紡涓闂
http(s) 锛氶氳繃鏈嶅姟鍣ㄥ彉閲 SERVER_PORT_SECURE 鍜 HTTPS 鍙垽鏂槸鍚﹀畨鍏ㄩ摼鎺ワ紝褰 HTTP 璇锋眰鏃讹紝SERVER_PORT_SECURE 涓0锛孒TTPS 涓 OFF锛屽惁鍒欎负 1 鍜 ON
鏈嶅姟鍣ㄥ彉閲 REQUEST_URI 鍙敤浜庤闂暣涓矾寰勶紝鍖呮嫭 <path> 鍜 <querystring>
ignoreCase 蹇界暐澶у皬鍐欙紝true 涓哄拷鐣
negate 鏄惁鍖归厤妯″紡锛屼负 true 鏃讹紝 褰 URL 涓庢寚瀹氭ā寮忎笉鍖归厤鏃讹紝鎵嶆墽琛屾搷浣
logicalGrouping 鏉′欢婊¤冻鎯呭喌锛屽鏋滀负 MatchAll 锛屾墍鏈夋潯浠堕兘蹇呴』婊¤冻锛孧atchAny 鑷冲皯婊¤冻涓涓潯浠
浠ヤ笅灞炴ф潵浣跨敤鏉′欢妯″紡
input 鍖归厤瀛楃涓
matchType 鍖归厤绫诲瀷
matchType 鍙堝垎涓 3 涓儏鍐
IsFile 鍒ゆ柇鏄惁涓哄疄闄呯殑鐗╃悊璺緞鏂囦欢锛宯egate 涓 true锛岃〃绀轰笉鏄枃浠
IsDirectory 鍒ゆ柇璇锋眰鐨勬槸鍚︿负瀹為檯鐨勭墿鐞嗚矾寰勭洰褰曪紝negate 涓 true锛岃〃绀轰笉鏄洰褰
Pattern 浣跨敤姝e垯琛ㄨ揪寮忎笌 input 瀛楃涓插尮閰嶏紝闇瑕佹坊鍔 pattern 灞炴т娇鐢ㄦ鍒
鎵ц閲嶅畾鍚戝姩浣滐紝url 灞炴т负閲嶅畾鍚戠殑璺緞
name=鈥漅ewrite鈥 閲嶅啓
name=鈥漅edirect鈥 閲嶅畾鍚
name=鈥滳ustomResponse鈥 鑷畾涔夊搷搴旓紝鍙戦 閿欒淇℃伅鐘舵佺爜
name=鈥滱bortRequest鈥 缁堟璇锋眰
redirectType 涓 Redirect 鎸囧畾鐘舵佺爜
301 鈥 Permanent 姘镐箙
302 鈥 Found 宸叉壘鍒
303 鈥 See other 鍙傞槄鍏朵粬
307 鈥 Temporary 涓存椂
寮曠敤鍙橀噺鐨勪娇鐢
褰 URL 涓庤鍒欐ā寮忔鍒欏尮閰嶆椂锛屽尮閰嶇粨鏋滀細鐢熸垚寮曠敤鍙橀噺锛屼緥瀛愯鏄
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
濡傛灉瀛楃涓叉槸锛歸ww.tianlunvip.com 浼氫骇鐢熶互涓嬪紩鐢ㄥ彉閲忕储寮
{C:0} - www.tianlunvip.com
{C:1} - www.
{C:2} - tianlunvip.com
瀵规潯浠舵ā寮忕殑鍚庡悜寮曠敤鐢 {C:N} 鏍囪瘑锛屽瑙勫垯妯″紡鐨勫悗鍚戝紩鐢ㄧ敤 {R:N} 鏍囪瘑锛屽叾涓 N 涓 0 鍒 9
鍏跺畠鍙敤鏈嶅姟鍣ㄥ彉閲
{CACHE_URL}
{DOCUMENT_ROOT}
{HTTP_URL}
{HTTP_HOST}
{PATH_INFO}
{PATH_TRANSLATED}
{QUERY_STRING}
{REQUEST_FILENAME}
{REQUEST_URI}
{SCRIPT_FILENAME}
{SCRIPT_NAME}
{SCRIPT_TRANSLATED}
{UNENCODED_URL}
{URL}
{URL_PATH_INFO}
{APP_POOL_ID}
{APPL_MD_PATH}
{APPL_PHYSICAL_PATH}
{GATEWAY_INTERFACE}
{SERVER_SOFTWARE}
{SSI_EXEC_DISABLED}
{HTTP_USER_AGENT}
瀹炴垬渚嬪瓙
1銆佸皢 HTTP 鐨勯摼鎺ラ噸瀹氬悜鍒 HTTTS 瀹夊叏閾炬帴
<rule name="301" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTPS}" pattern="^ON$" negate="true" /> </conditions> <action type="Redirect" url="https://www.tianlunvip.com/{R:1}" redirectType="Permanent" /> </rule>
2銆佸皢 www.foo.com 鍩熷悕閲嶅畾鍚戝埌 www.tianlunvip.com
<rule name="301" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAny"> <add input="{HTTP_HOST}" pattern="^www.foo.com$" /> </conditions> <action type="Redirect" url="https://www.tianlunvip.com/{R:0}" redirectType="Permanent" /> </rule>
3銆佺敤鐭摼鎺ユ浛浠g湡瀹為摼鎺ュ湴鍧
<rule name="Rewrite" stopProcessing="true"> <match url="^post\/(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="post/index.php?p={R:2}" /> </rule>
浠ヤ笂灏辨槸web.config 閲嶅啓瑙勫垯璇﹁В鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒