今個在群里有朋友問到:在html后綴后面,隨便加數字,網頁還可以正常打開,比如http://www.kredytypozyczki.net/mysql/blog-1043.html,在后面加數字或其他內容,如blog-1043.html123,blog-104.htmlxxx,這種是錯誤,為啥不提示錯誤呢?
熱心的朋友不少,有的說“自定義一個錯誤吧,正則 檢測 當前域名,html后面有東西,就執行。在中間件判斷一下也可以實現”。也有朋友提到是偽靜態的問題,但沒進一步說明,于是我直接就想到,偽靜態中.html$沒有結束,寫成了.html。測試發現正是偽靜態設置錯誤導致網址后面加任意字符都能訪問的錯誤。
順便提一下偽靜態,開始和結束符號都是很重要的,如下一段簡單的代碼:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <httpErrors errorMode="DetailedLocalOnly" /> <rewrite> <rules> <!--類目--> <rule name="clas" stopProcessing="true"> <match url="^(.*)/$" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> <action type="Rewrite" url="index.php/Index/plist/t/{R:1}" /> </rule> <!--詳情--> <rule name="pshow" stopProcessing="true"> <match url="^pshow-([\d]+).html$" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> <action type="Rewrite" url="index.php/Index/pshow/id/{R:1}" /> </rule> <!--文章--> <rule name="ashow" stopProcessing="true"> <match url="^ashow-([\d]+).html$" /> <conditions logicalGrouping="MatchAll" trackAllCaptures="false" /> <action type="Rewrite" url="index.php/Index/ashow/id/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
© 致遠 2020-05-19,原創內容,轉載請注明出錯:網址后面加任意字符都能訪問的錯誤