<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <outboundRules> <preConditions> <preCondition name="ResponseIsHtml1"> <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/> </preCondition> </preConditions> </outboundRules> <rules> <clear/> <rule name="thinkphp"> <match url="^(?!css)(.*).html$"/> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/> <action type="Rewrite" url="/index.php?s={R:1}"/> </rule> <rule name="thinkphp"> <match url="^(?!Public)(.*).html$"/> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/> <action type="Rewrite" url="/index.php?s={R:1}"/> </rule> </rules> </rewrite> <httpErrors> <remove statusCode="404" subStatusCode="-1"/> <error statusCode="404" prefixLanguageFilePath="" path="/error/404.php" responseMode="ExecuteURL"/> </httpErrors> </system.webServer> </configuration>
last,重寫后的規(guī)則,會繼續(xù)用重寫后的值去匹配下面的location。 break,重寫后的規(guī)則,不會去匹配下面的location。使用新的規(guī)則,直接發(fā)起一次http請求了。 錯誤頁指定conf/nginx.conf設(shè)置:error_page 404 500 = /error.html 或 error_page 404 = http://域名; rewrite '(?!css)(.*).html' /index.php?s=$1 last; rewrite '(?!Public)(.*).html' /index.php?s=$1 last;
1) R[=code](force redirect) 強制外部重定向 強制在替代字符串加上http://thishost[:thisport]/前綴重定向到外部的URL.如果code不指定,將用缺省的302 HTTP狀態(tài)碼。 2) F(force URL to be forbidden)禁用URL,返回403HTTP狀態(tài)碼。 3) G(force URL to be gone) 強制URL為GONE,返回410HTTP狀態(tài)碼。 4) P(force proxy) 強制使用代理轉(zhuǎn)發(fā)。 5) L(last rule) 表明當前規(guī)則是最后一條規(guī)則,停止分析以后規(guī)則的重寫。 6) N(next round) 重新從第一條規(guī)則開始運行重寫過程。 7) C(chained with next rule) 與下一條規(guī)則關(guān)聯(lián) 8) QSA 繼續(xù)傳遞GET參數(shù) RewriteRule規(guī)則表達式的說明: . 匹配任何單字符 [chars] 匹配字符串:chars [^chars] 不匹配字符串:chars text1|text2 可選擇的字符串:text1或text2 ? 匹配0到1個字符 * 匹配0到多個字符 + 匹配1到多個字符 ^ 字符串開始標志 $ 字符串結(jié)束標志 n 轉(zhuǎn)義符標志 RewriteEngine On RewriteRule (?!css)(.*).html$ /index.php?s=$1 [L] RewriteRule (?!Public)(.*).html$ /index.php?s=$1 [L] ErrorDocument 404 /error/404.php
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <clear/> <rule name="thinkphp"> <match url="^(?!Public)(.*).html$"/> <conditions logicalGrouping="MatchAll" trackAllCaptures="false"/> <action type="Rewrite" url="/index.php?s={R:1}"/> </rule> </rules> </rewrite> </system.webServer> </configuration>