{"id":109001,"date":"2011-06-27T19:28:45","date_gmt":"2011-06-27T11:28:45","guid":{"rendered":"\/2011\/06\/27\/nginx_rewrite.html"},"modified":"2011-06-27T19:28:45","modified_gmt":"2011-06-27T11:28:45","slug":"nginx_rewrite","status":"publish","type":"post","link":"https:\/\/blog.zhenglei.net\/?p=109001","title":{"rendered":"nginx rewrite\u89c4\u5219\u548c\u53c2\u8003"},"content":{"rendered":"<p><a href=\"http:\/\/edu.codepub.com\/show.php?contentid=25477\">http:\/\/edu.codepub.com\/show.php?contentid=25477<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\uff0c\u5176\u4e2d\uff1a<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">* ~ \u4e3a\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d<\/li>\n<li>* ~* \u4e3a\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u5339\u914d<\/li>\n<li>* !~\u548c!~*\u5206\u522b\u4e3a\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d\u53ca\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u4e0d\u5339\u914d<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u6587\u4ef6\u53ca\u76ee\u5f55\u5339\u914d\uff0c\u5176\u4e2d\uff1a<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">* -f\u548c!-f\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u6587\u4ef6<\/li>\n<li>* -d\u548c!-d\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u76ee\u5f55<\/li>\n<li>* -e\u548c!-e\u7528\u6765\u5224\u65ad\u662f\u5426\u5b58\u5728\u6587\u4ef6\u6216\u76ee\u5f55<\/li>\n<li>* -x\u548c!-x\u7528\u6765\u5224\u65ad\u6587\u4ef6\u662f\u5426\u53ef\u6267\u884c<\/li>\n<\/ol>\n<\/div>\n<p><strong>flag\u6807\u8bb0\u6709\uff1a<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">* last \u76f8\u5f53\u4e8eApache\u91cc\u7684[L]\u6807\u8bb0\uff0c\u8868\u793a\u5b8c\u6210rewrite<\/li>\n<li>* break \u7ec8\u6b62\u5339\u914d, \u4e0d\u518d\u5339\u914d\u540e\u9762\u7684\u89c4\u5219<\/li>\n<li>* redirect \u8fd4\u56de302\u4e34\u65f6\u91cd\u5b9a\u5411 \u5730\u5740\u680f\u4f1a\u663e\u793a\u8df3\u8f6c\u540e\u7684\u5730\u5740<\/li>\n<li>* permanent \u8fd4\u56de301\u6c38\u4e45\u91cd\u5b9a\u5411 \u5730\u5740\u680f\u4f1a\u663e\u793a\u8df3\u8f6c\u540e\u7684\u5730\u5740<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u4e00\u4e9b\u53ef\u7528\u7684\u5168\u5c40\u53d8\u91cf\u6709\uff0c\u53ef\u4ee5\u7528\u505a\u6761\u4ef6\u5224\u65ad(\u5f85\u8865\u5168)<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">$args<\/li>\n<li>$content_length<\/li>\n<li>$content_type<\/li>\n<li>$document_root<\/li>\n<li>$document_uri<\/li>\n<li>$host<\/li>\n<li>$http_user_agent<\/li>\n<li>$http_cookie<\/li>\n<li>$limit_rate<\/li>\n<li>$request_body_file<\/li>\n<li>$request_method<\/li>\n<li>$remote_addr<\/li>\n<li>$remote_port<\/li>\n<li>$remote_user<\/li>\n<li>$request_filename<\/li>\n<li>$request_uri<\/li>\n<li>$query_string<\/li>\n<li>$scheme<\/li>\n<li>$server_protocol<\/li>\n<li>$server_addr<\/li>\n<li>$server_name<\/li>\n<li>$server_port<\/li>\n<li>$uri<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7ed3\u5408QeePHP\u7684\u4f8b\u5b50<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">if (!-d $request_filename) {<\/li>\n<li>rewrite ^\/([a-z-A-Z]+)\/([a-z-A-Z]+)\/?(.*)$ \/index.php?namespace=user&amp;amp;controller=$1&amp;amp;action=$2&amp;amp;$3 last;<\/li>\n<li>rewrite ^\/([a-z-A-Z]+)\/?$ \/index.php?namespace=user&amp;amp;controller=$1 last;<\/li>\n<li>break;<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u591a\u76ee\u5f55\u8f6c\u6210\u53c2\u6570<\/strong><br \/> abc.domian.com\/sort\/2 =&gt; abc.domian.com\/index.php?act=sort&amp;name=abc&amp;id=2<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">if ($host ~* (.*).domain.com) {<\/li>\n<li>set $sub_name $1;&nbsp; &nbsp;<\/li>\n<li>rewrite ^\/sort\/(d+)\/?$ \/index.php?act=sort&amp;cid=$sub_name&amp;id=$1 last;<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u76ee\u5f55\u5bf9\u6362<\/strong><br \/> \/123456\/xxxx -&gt; \/xxxx?id=123456<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">rewrite ^\/(d+)\/(.+)\/ \/$2?id=$1 last;<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u4f8b\u5982\u4e0b\u9762\u8bbe\u5b9anginx\u5728\u7528\u6237\u4f7f\u7528ie\u7684\u4f7f\u7528\u91cd\u5b9a\u5411\u5230\/nginx-ie\u76ee\u5f55\u4e0b\uff1a<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">if ($http_user_agent ~ MSIE) {<\/li>\n<li>rewrite ^(.*)$ \/nginx-ie\/$1 break;<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u76ee\u5f55\u81ea\u52a8\u52a0&ldquo;\/&rdquo;<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">if (-d $request_filename){<\/li>\n<li>rewrite ^\/(.*)([^\/])$ http:\/\/$host\/$1$2\/ permanent;<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7981\u6b62htaccess<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ~\/.ht {<\/li>\n<li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deny all;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7981\u6b62\u591a\u4e2a\u76ee\u5f55<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ~ ^\/(cron|templates)\/ {<\/li>\n<li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deny all;<\/li>\n<li>break;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7981\u6b62\u4ee5\/data\u5f00\u5934\u7684\u6587\u4ef6<\/strong><br \/> \u53ef\u4ee5\u7981\u6b62\/data\/\u4e0b\u591a\u7ea7\u76ee\u5f55\u4e0b.log.txt\u7b49\u8bf7\u6c42;<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ~ ^\/data {<\/li>\n<li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deny all;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7981\u6b62\u5355\u4e2a\u76ee\u5f55<\/strong><br \/> \u4e0d\u80fd\u7981\u6b62.log.txt\u80fd\u8bf7\u6c42<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location \/searchword\/cron\/ {<\/li>\n<li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deny all;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7981\u6b62\u5355\u4e2a\u6587\u4ef6<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ~ \/data\/sql\/data.sql {<\/li>\n<li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deny all;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7ed9favicon.ico\u548crobots.txt\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4;<\/strong><br \/> \u8fd9\u91cc\u4e3afavicon.ico\u4e3a99\u5929,robots.txt\u4e3a7\u5929\u5e76\u4e0d\u8bb0\u5f55404\u9519\u8bef\u65e5\u5fd7<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ~(favicon.ico) {<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log_not_found off;<\/li>\n<li>expires 99d;<\/li>\n<li>break;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp; &nbsp; &nbsp;location ~(robots.txt) {<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log_not_found off;<\/li>\n<li>expires 7d;<\/li>\n<li>break;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u8bbe\u5b9a\u67d0\u4e2a\u6587\u4ef6\u7684\u8fc7\u671f\u65f6\u95f4;\u8fd9\u91cc\u4e3a600\u79d2\uff0c\u5e76\u4e0d\u8bb0\u5f55\u8bbf\u95ee\u65e5\u5fd7<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ^~ \/html\/scripts\/loadhead_1.js {<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_log&nbsp; &nbsp;off;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root \/opt\/lampp\/htdocs\/web;<\/li>\n<li>expires 600;<\/li>\n<li>break;<\/li>\n<li>&nbsp; &nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u6587\u4ef6\u53cd\u76d7\u94fe\u5e76\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4<\/strong><br \/> \u8fd9\u91cc\u7684return 412 \u4e3a\u81ea\u5b9a\u4e49\u7684http\u72b6\u6001\u7801\uff0c\u9ed8\u8ba4\u4e3a403\uff0c\u65b9\u4fbf\u627e\u51fa\u6b63\u786e\u7684\u76d7\u94fe\u7684\u8bf7\u6c42<br \/> &ldquo;rewrite ^\/ http:\/\/leech.c1gstudio.com\/leech.gif;&rdquo;\u663e\u793a\u4e00\u5f20\u9632\u76d7\u94fe\u56fe\u7247<br \/> &ldquo;access_log off;&rdquo;\u4e0d\u8bb0\u5f55\u8bbf\u95ee\u65e5\u5fd7\uff0c\u51cf\u8f7b\u538b\u529b<br \/> &ldquo;expires 3d&rdquo;\u6240\u6709\u6587\u4ef63\u5929\u7684\u6d4f\u89c8\u5668\u7f13\u5b58<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ~* ^.+.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {<\/li>\n<li>valid_referers none blocked *.c1gstudio.com *.c1gstudio.net localhost 208.97.167.194;<\/li>\n<li>if ($invalid_referer) {<\/li>\n<li>&nbsp; &nbsp; rewrite ^\/ http:\/\/leech.c1gstudio.com\/leech.gif;<\/li>\n<li>&nbsp; &nbsp; return 412;<\/li>\n<li>&nbsp; &nbsp; break;<\/li>\n<li>}<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_log&nbsp; &nbsp;off;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root \/opt\/lampp\/htdocs\/web;<\/li>\n<li>expires 3d;<\/li>\n<li>break;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u53ea\u5145\u8bb8\u56fa\u5b9aip\u8bbf\u95ee\u7f51\u7ad9\uff0c\u5e76\u52a0\u4e0a\u5bc6\u7801<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">root&nbsp; \/opt\/htdocs\/www;<\/li>\n<li>allow&nbsp; &nbsp;208.97.167.194;<\/li>\n<li>allow&nbsp; &nbsp;222.33.1.2;<\/li>\n<li>allow&nbsp; &nbsp;231.152.49.4;<\/li>\n<li>deny&nbsp; &nbsp; all;<\/li>\n<li>auth_basic &#8220;C1G_ADMIN&#8221;;<\/li>\n<li>auth_basic_user_file htpasswd;<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u5c06\u591a\u7ea7\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u8f6c\u6210\u4e00\u4e2a\u6587\u4ef6\uff0c\u589e\u5f3aseo\u6548\u679c<\/strong><br \/> \/job-123-456-789.html \u6307\u5411\/job\/123\/456\/789.html<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">rewrite ^\/job-([0-9]+)-([0-9]+)-([0-9]+).html$ \/job\/$1\/$2\/jobshow_$3.html last;<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u5c06\u6839\u76ee\u5f55\u4e0b\u67d0\u4e2a\u6587\u4ef6\u5939\u6307\u54112\u7ea7\u76ee\u5f55<\/strong><br \/> \u5982\/<strong>shanghai<\/strong>job\/ \u6307\u5411 \/area\/<strong>shanghai<\/strong>\/<br \/> \u5982\u679c\u4f60\u5c06last\u6539\u6210permanent\uff0c\u90a3\u4e48\u6d4f\u89c8\u5668\u5730\u5740\u680f\u663e\u662f\/location\/shanghai\/<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">rewrite ^\/([0-9a-z]+)job\/(.*)$ \/area\/$1\/$2 last;<\/li>\n<\/ol>\n<\/div>\n<p>\u4e0a\u9762\u4f8b\u5b50\u6709\u4e2a\u95ee\u9898\u662f\u8bbf\u95ee\/shanghai \u65f6\u5c06\u4e0d\u4f1a\u5339\u914d<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">rewrite ^\/([0-9a-z]+)job$ \/area\/$1\/ last;<\/li>\n<li>rewrite ^\/([0-9a-z]+)job\/(.*)$ \/area\/$1\/$2 last;<\/li>\n<\/ol>\n<\/div>\n<p>\u8fd9\u6837\/shanghai \u4e5f\u53ef\u4ee5\u8bbf\u95ee\u4e86\uff0c\u4f46\u9875\u9762\u4e2d\u7684\u76f8\u5bf9\u94fe\u63a5\u65e0\u6cd5\u4f7f\u7528\uff0c<br \/> \u5982.\/list_1.html\u771f\u5b9e\u5730\u5740\u662f\/area\/shanghia\/list_1.html\u4f1a\u53d8\u6210\/list_1.html,\u5bfc\u81f3\u65e0\u6cd5\u8bbf\u95ee\u3002<\/p>\n<p>\u90a3\u6211\u52a0\u4e0a\u81ea\u52a8\u8df3\u8f6c\u4e5f\u662f\u4e0d\u884c\u54af<br \/> (-d $request_filename)\u5b83\u6709\u4e2a\u6761\u4ef6\u662f\u5fc5\u9700\u4e3a\u771f\u5b9e\u76ee\u5f55\uff0c\u800c\u6211\u7684rewrite\u4e0d\u662f\u7684\uff0c\u6240\u4ee5\u6ca1\u6709\u6548\u679c<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">if (-d $request_filename){<\/li>\n<li>rewrite ^\/(.*)([^\/])$ http:\/\/$host\/$1$2\/ permanent;<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n<p>\u77e5\u9053\u539f\u56e0\u540e\u5c31\u597d\u529e\u4e86\uff0c\u8ba9\u6211\u624b\u52a8\u8df3\u8f6c\u5427<\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">rewrite ^\/([0-9a-z]+)job$ \/$1job\/ permanent;<\/li>\n<li>rewrite ^\/([0-9a-z]+)job\/(.*)$ \/area\/$1\/$2 last;<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u6587\u4ef6\u548c\u76ee\u5f55\u4e0d\u5b58\u5728\u7684\u65f6\u5019\u91cd\u5b9a\u5411\uff1a<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">if (!-e $request_filename) {<\/li>\n<li>proxy_pass http:\/\/127.0.0.1;<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u57df\u540d\u8df3\u8f6c<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">server<\/li>\n<li>&nbsp;&nbsp; &nbsp; {<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listen&nbsp; &nbsp; &nbsp; &nbsp;80;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; server_name&nbsp; jump.c1gstudio.com;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index index.html index.htm index.php;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root&nbsp; \/opt\/lampp\/htdocs\/www;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rewrite ^\/ http:\/\/www.c1gstudio.com\/;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_log&nbsp; off;<\/li>\n<li>&nbsp;&nbsp; &nbsp; }<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u591a\u57df\u540d\u8f6c\u5411<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">server_name&nbsp; www.c1gstudio.com www.c1gstudio.net;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index index.html index.htm index.php;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root&nbsp; \/opt\/lampp\/htdocs;<\/li>\n<li>if ($host ~ &#8220;c1gstudio.net&#8221;) {<\/li>\n<li>rewrite ^(.*) http:\/\/www.c1gstudio.com$1 permanent;<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u4e09\u7ea7\u57df\u540d\u8df3\u8f6c<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">if ($http_host ~* &#8220;^(.*).i.c1gstudio.com$&#8221;) {<\/li>\n<li>rewrite ^(.*) http:\/\/top.yingjiesheng.com$1;<\/li>\n<li>break;<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u57df\u540d\u955c\u5411<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">server<\/li>\n<li>&nbsp;&nbsp; &nbsp; {<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; listen&nbsp; &nbsp; &nbsp; &nbsp;80;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; server_name&nbsp; mirror.c1gstudio.com;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; index index.html index.htm index.php;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root&nbsp; \/opt\/lampp\/htdocs\/www;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rewrite ^\/(.*) http:\/\/www.c1gstudio.com\/$1 last;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access_log&nbsp; off;<\/li>\n<li>&nbsp;&nbsp; &nbsp; }<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u67d0\u4e2a\u5b50\u76ee\u5f55\u4f5c\u955c\u5411<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ^~ \/zhaopinhui {<\/li>\n<li>&nbsp; rewrite ^.+ http:\/\/zph.c1gstudio.com\/ last;<\/li>\n<li>&nbsp; break;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>discuz ucenter home (uchome) rewrite<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">rewrite ^\/(space|network)-(.+).html$ \/$1.php?rewrite=$2 last;<\/li>\n<li>rewrite ^\/(space|network).html$ \/$1.php last;<\/li>\n<li>rewrite ^\/([0-9]+)$ \/space.php?uid=$1 last;<\/li>\n<\/ol>\n<\/div>\n<p><strong>discuz 7 rewrite<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">rewrite ^(.*)\/archiver\/((fid|tid)-[w-]+.html)$ $1\/archiver\/index.php?$2 last;<\/li>\n<li>rewrite ^(.*)\/forum-([0-9]+)-([0-9]+).html$ $1\/forumdisplay.php?fid=$2&amp;page=$3 last;<\/li>\n<li>rewrite ^(.*)\/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1\/viewthread.php?tid=$2&amp;extra=page%3D$4&amp;page=$3 last;<\/li>\n<li>rewrite ^(.*)\/profile-(username|uid)-(.+).html$ $1\/viewpro.php?$2=$3 last;<\/li>\n<li>rewrite ^(.*)\/space-(username|uid)-(.+).html$ $1\/space.php?$2=$3 last;<\/li>\n<li>rewrite ^(.*)\/tag-(.+).html$ $1\/tag.php?name=$2 last;<\/li>\n<\/ol>\n<\/div>\n<p><strong>\u7ed9discuz\u67d0\u7248\u5757\u5355\u72ec\u914d\u7f6e\u57df\u540d<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">server_name&nbsp; bbs.c1gstudio.com news.c1gstudio.com;<\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp; &nbsp; &nbsp;location = \/ {<\/li>\n<li>&nbsp; &nbsp; &nbsp; &nbsp; if ($http_host ~ news.c1gstudio.com$) {<\/li>\n<li>&nbsp; rewrite ^.+ http:\/\/news.c1gstudio.com\/forum-831-1.html last;<\/li>\n<li>&nbsp; break;<\/li>\n<li>}<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<\/ol>\n<\/div>\n<p><strong>discuz ucenter \u5934\u50cf rewrite \u4f18\u5316<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ^~ \/ucenter {<\/li>\n<li>&nbsp; &nbsp; &nbsp;location ~ .*.php?$<\/li>\n<li>&nbsp; &nbsp; &nbsp;{<\/li>\n<li>&nbsp; #fastcgi_pass&nbsp; unix:\/tmp\/php-cgi.sock;<\/li>\n<li>&nbsp; fastcgi_pass&nbsp; 127.0.0.1:9000;<\/li>\n<li>&nbsp; fastcgi_index index.php;<\/li>\n<li>&nbsp; include fcgi.conf;&nbsp; &nbsp; &nbsp;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp; &nbsp; &nbsp;location \/ucenter\/data\/avatar {<\/li>\n<li>log_not_found off;<\/li>\n<li>access_log&nbsp; &nbsp;off;<\/li>\n<li>location ~ \/(.*)_big.jpg$ {<\/li>\n<li>&nbsp; &nbsp; error_page 404 \/ucenter\/images\/noavatar_big.gif;<\/li>\n<li>}<\/li>\n<li>location ~ \/(.*)_middle.jpg$ {<\/li>\n<li>&nbsp; &nbsp; error_page 404 \/ucenter\/images\/noavatar_middle.gif;<\/li>\n<li>}<\/li>\n<li>location ~ \/(.*)_small.jpg$ {<\/li>\n<li>&nbsp; &nbsp; error_page 404 \/ucenter\/images\/noavatar_small.gif;<\/li>\n<li>}<\/li>\n<li>expires 300;<\/li>\n<li>break;<\/li>\n<li>&nbsp; &nbsp; &nbsp;}<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/li>\n<\/ol>\n<\/div>\n<p><strong>jspace rewrite<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location ~ .*.php?$<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#fastcgi_pass&nbsp; unix:\/tmp\/php-cgi.sock;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_pass&nbsp; 127.0.0.1:9000;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_index index.php;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;include fcgi.conf;&nbsp; &nbsp; &nbsp;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/li>\n<li>&nbsp;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; location ~* ^\/index.php\/<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/li>\n<li>&nbsp;&nbsp; &nbsp;rewrite ^\/index.php\/(.*) \/index.php?$1 break;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_pass&nbsp; 127.0.0.1:9000;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_index index.php;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;include fcgi.conf;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/li>\n<\/ol>\n<\/div>\n<p><strong>wordpress rewrite<\/strong><\/p>\n<div class=\"hl-surround\">\n<ol class=\"hl-main ln-show\" title=\"Double click to hide line number.\">\n<li class=\"hl-firstline\">location \/ {<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;index index.html index.php;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (-f $request_filename\/index.html){<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rewrite (.*) $1\/index.html break;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if (-f $request_filename\/index.php){<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rewrite (.*) $1\/index.php;<\/li>\n<li>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<\/li>\n<li>if&nbsp; (!-e $request_filename)<\/li>\n<li>{<\/li>\n<li>&nbsp; &nbsp; rewrite (.*) \/index.php;<\/li>\n<li>}<\/li>\n<li>}<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u81ea http:\/\/edu.codepub.com\/show.php?contentid=25477, \u4ee5\u65b9\u4fbf\u67e5\u627e <a href=\"https:\/\/blog.zhenglei.net\/?p=109001\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[80],"class_list":["post-109001","post","type-post","status-publish","format-standard","hentry","category-html","tag-rewrite"],"_links":{"self":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/109001","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=109001"}],"version-history":[{"count":0,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=\/wp\/v2\/posts\/109001\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=109001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=109001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhenglei.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=109001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}