要將http://dede.com/index.php?t=3用偽靜態規則改寫成http://dede.com/t3.html,即可在nginx的conf/nginx.conf里面添加即可。
在location / {}里添加,如:
location / {
root D:/phpweb/wwwroot;
index index.php index.html index.htm;
rewrite ^(.*)/t(\d+)\.html$ $1/index.php?t=3 last;
}
仔細觀察 rewrite ^(.*)/t(\d+)\.html$ $1/index.php?t=3 last;其實感覺nginx的偽靜態規則蠻好寫的。就是用正則的基礎上,一個rewrite來聲明,然后^是偽靜態規則開頭,(.*)匹配任意字符,這里匹配的就是域名了,t就是你在這里想加的字符,如你可以加apple、orange這樣的分類名了,(\d+)匹配的是數字,\.html匹配的是后綴,$就是正則匹配的結束。后面半部分就是要改寫的url了,用$1打頭,表示域名,/index.php?t=3就是要改寫的URL,用last;結束即可。