棣栧厛鏉ョ湅涓涓 web.config 鍩烘湰鏂囦欢鏍煎紡

<?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浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=227