nginx rewite 規則,官方文檔:http://wiki.nginx.org/NginxHttpRewriteModule

nginx rewrite規則格式:rewrite regex replacement flag

flag標記有四種格式:

last – 相當于Apache中的L
break – 中止Rewirte,不在繼續匹配
redirect – 返回臨時重定向的HTTP狀態302,相當于Apache中的R
permanent – 返回永久重定向的HTTP狀態301,相當于Apache中的R=301

可以放在server, location 和 if 模塊中。

匹配判斷:

~ 為區分大小寫匹配; !~為區分大小寫不匹配

~* 為不區分大小寫匹配;!~為不區分大小寫不匹配

例如,設定nginx在用戶使用ie的使用重定向到/nginx-ie目錄下:

if ($http_user_agent ~ MSIE) {
rewrite ^(.*)$ /msie/$1 break;
}

附,常用nginx Rewrite 規則配置代碼。

1、只使用一個網址,比如主力網址設為www.shinetop.cn

if ($host != 'www.shinetop.cn' ) {
rewrite ^/(.*)$ http://www.shinetop.cn/$1 permanent;
}

訪問35.com時,會自動跳轉到www.shinetop.cn

2、防盜鏈

location ~* .(gif|jpg|png|swf|flv)$ {
valid_referers none blocked 35.com dgjs123.com;
if ($invalid_referer) {
return 403;
}
}

盜鏈時則返回403錯誤,允許的域名可以直接跟在第二行的域名后面。

3、WordPress的Rewrite

location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

目前,代碼收藏上就是使用的這段代碼。

4.bo-blog在nginx下nginx rewrite 規則

if (!-e $request_filename) {
rewrite ^/post/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?entryid=$1&page=$2&part=$3 last;
rewrite ^/page/([0-9]+)/([0-9]+)/?$ /index.php?mode=$1&page=$2 last;
rewrite ^/starred/([0-9]+)/?([0-9]+)?/?$ /star.php?mode=$1&page=$2 last;
rewrite ^/category/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=category_$1&mode=$2&page=$3 last;
rewrite ^/archiver/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=archive&cm=$1&cy=$2&mode=$3&page=$4 last;
rewrite ^/date/([0-9]+)/([0-9]+)/([0-9]+)/?([0-9]+)?/?([0-9]+)?/?$ /index.php?go=showday_$1-$2-$3&mode=$4&page=$5 last;
rewrite ^/user/([0-9]+)/?$ /view.php?go=user_$1 last;
rewrite ^/tags/([^/]+)/?([0-9]+)?/?([0-9]+)?/?$ /tag.php?tag=$1&mode=$2&page=$3 last;
rewrite ^/component/id/([0-9]+)/?$ /page.php?pageid=$1 last;
rewrite ^/component/([^/]+)/?$ /page.php?pagealias=$1 last;
#Force redirection for old rules
rewrite ^/read\.php/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
rewrite ^/post/([0-9]+)\.htm$ http://$host/post/$1/ permanent;
rewrite ^/post/([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/ permanent;
rewrite ^/post/([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/post/$1/$2/$3/ permanent;
rewrite ^/index\_([0-9]+)\_([0-9]+)\.htm$ http://$host/page/$1/$2/ permanent;
rewrite ^/star\_([0-9]+)\_([0-9]+)\.htm$ http://$host/starred/$1/$2/ permanent;
rewrite ^/category\_([0-9]+)\.htm$ http://$host/category/$1/ permanent;
rewrite ^/category\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/category/$1/$2/$3/ permanent;
rewrite ^/archive\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/ permanent;
rewrite ^/archive\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/archiver/$1/$2/$3/$4/ permanent;
rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/ permanent;
rewrite ^/showday\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\_([0-9]+)\.htm$ http://$host/date/$1/$2/$3/$4/$5/ permanent;
#Filename alias
rewrite ^/([a-zA-Z0-9_-]+)/?([0-9]+)?/?([0-9]+)?/?$ /read.php?blogalias=$1&page=$2&part=$3 last;
}
贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » nginx rewrite重寫規則與防盜鏈配置方法教程詳解

登錄

找回密碼

注冊

主站蜘蛛池模板: 久久久精品人妻一区二区三区蜜桃| 亚洲码和欧洲码一二三四| 99久久国产综合精品女图图等你| 国产成人午夜精品影院| 大香j蕉75久久精品免费8| 激情偷乱人成视频在线观看| 欧美在线观看www| 产综合无码一区| 亚洲国产精品无码观看久久| 国产亚洲精品成人av在线| 一区二区不卡国产精品| 国产一区国产二区在线视频| 最新国产精品亚洲| 国产AV影片麻豆精品传媒| 在线看国产精品自拍内射| 国产国产乱老熟女视频网站97| 久久天天躁夜夜躁狠狠躁2022| 成人亚洲国产精品一区不卡| 国产无遮挡免费视频免费| 亚洲国产高清在线观看视频| 亚洲一区二区三区蜜桃臀| 亚洲av激情五月性综合| 亚洲精品美女久久久久9999| 婷婷六月天在线| 成年性午夜免费视频网站| 色秀网在线观看视频免费| 又粗又硬又黄a级毛片| 国产suv精品一区二区四 | 国产精品一区二区小视频| 日本不卡的一区二区三区| 欧美人成在线播放网站免费| аⅴ天堂中文在线网| 襄樊市| 亚洲人妻中文字幕一区| 成人午夜大片免费看爽爽爽| 精品国产人妻一区二区三区久久 | 麻豆国产黄色一级免费片| 亚洲人妻精品中文字幕| 公天天吃我奶躁我的在线观看| 69精品丰满人妻无码视频a片| 99久久激情国产精品|