{"id":627,"date":"2012-08-14T16:47:40","date_gmt":"2012-08-14T08:47:40","guid":{"rendered":"http:\/\/hesiway.tk\/?p=627"},"modified":"2012-08-14T16:47:40","modified_gmt":"2012-08-14T08:47:40","slug":"%e6%96%b0%e6%b5%aa-sae-appconfig-%e6%9c%8d%e5%8a%a1","status":"publish","type":"post","link":"http:\/\/hesiwei.cn\/?p=627","title":{"rendered":"\u65b0\u6d6a sae AppConfig \u670d\u52a1"},"content":{"rendered":"<p><strong>\u670d\u52a1\u6982\u8981<\/strong><\/p>\n<p>AppConfig\u670d\u52a1\u662fSAE\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u7684\u5bf9web\u670d\u52a1\u5668\u8fdb\u884c\u81ea\u5b9a\u4e49\u914d\u7f6e\u7684\u529f\u80fd\uff0c\u4f7f\u7528AppConfig\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u5b9e\u73b0\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p>\n<ol>\n<li>\u00a0\u76ee\u5f55\u9ed8\u8ba4\u9875\u9762<\/li>\n<li>\u00a0\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762<\/li>\n<li>\u00a0\u538b\u7f29<\/li>\n<li>\u00a0\u9875\u9762\u91cd\u5b9a\u5411<\/li>\n<li>\u00a0\u9875\u9762\u8fc7\u671f<\/li>\n<li>\u00a0\u8bbe\u7f6e\u54cd\u5e94\u5934\u7684content-type<\/li>\n<li>\u00a0\u8bbe\u7f6e\u9875\u9762\u8bbf\u95ee\u6743\u9650<\/li>\n<\/ol>\n<p>\u4ece\u4e0a\u9762\u7684\u8bf4\u660e\u53ef\u4ee5\u770b\u51fa\uff0cAppConfig\u53ef\u4ee5\u5b8c\u5168\u4ee3\u66ffhtaccess\u7684\u5e38\u89c1\u529f\u80fd\uff0c\u5176\u5b9eAppConfig\u6b63\u662fSAE\u4e3a\u4e86\u66ff\u4ee3\u4f20\u7edfapache htaccess\u800c\u5b9e\u73b0\u7684\u529f\u80fd\uff0c\u539f\u56e0\u6709\u4e24\u70b9\uff1a<\/p>\n<p>1. \u4f20\u7edfhtaccess\u6548\u7387\u4e0d\u9ad8\uff0c\u56e0\u4e3a\u5176\u9488\u5bf9\u6240\u6709\u76ee\u5f55\u8fdb\u884c\u9012\u5f52merge<br \/>\n2. \u4f20\u7edfhtaccess\u8fc7\u4e8e\u590d\u6742\uff0c\u5b66\u4e60\u6210\u672c\u9ad8\u3002AppConfig\u5177\u6709\u6548\u7387\u9ad8\u800c\u4e14\u5b66\u4e60\u6210\u672c\u4f4e\u7684\u7279\u70b9\uff0cAppConfig\u53ea\u5728App\u8bbf\u95ee\u65f6\u9488\u5bf9\u6839\u76ee\u5f55\u751f\u6210\u4e00\u6b21\u89c4\u5219\uff0c\u800c\u4e14AppConfig\u91c7\u7528\u7c7b\u81ea\u7136\u8bed\u8a00\u7684\u89c4\u5219\u63cf\u8ff0\uff0c\u5f00\u53d1\u8005\u53ea\u9700\u8981\u53c2\u8003\u51e0\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u5373\u53ef\u719f\u6089\u4f7f\u7528\u3002<\/p>\n<p><!--more--><\/p>\n<p><strong>\u4f7f\u7528\u6307\u5357<\/strong><\/p>\n<p>\u4f8b\u5b50\uff1a<br \/>\nappname: saetest<br \/>\nversion: 1<br \/>\n\u7f16\u8f91saetest\/1\/config.yaml\uff0c\u589e\u52a0handle\u6bb5\uff0c\u5982\uff1a<br \/>\nname: saetest<br \/>\nversion: 1<br \/>\nhandle:<br \/>\n&#8211; rewrite: if(!is_dir() &amp;&amp; !is_file()) goto &#8220;index.php?%{QUERY_STRING}&#8221;<br \/>\n\u7f16\u8f91\u5b8c\u6210\u540e\uff0c\u901a\u8fc7SVN\u4ee3\u7801\u90e8\u7f72\u5de5\u5177\u63d0\u4ea4\u5373\u53ef\u751f\u6548\u3002\u6216\u8005\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5728\u7ebf\u4ee3\u7801\u7f16\u8f91\u5668\u4fee\u6539config.yaml<br \/>\n\u5982\u679c\u901a\u8fc7SVN\u90e8\u7f72\uff0c\u53ea\u9700\u8981\u5728\u9ed8\u8ba4\u7248\u672c\u6240\u5728\u76ee\u5f55\u4e0b\uff0c\u5982\uff0c\u60a8\u7684\u5e94\u7528\u540d\u4e3adevapp\uff0c\u9ed8\u8ba4\u7248\u672c\u662f3\uff0c\u90a3\u4e48\u8bf7\u5728devapp\/3\/\u4e0b\u521b\u5efaconfig.yaml\u6587\u4ef6\uff0c\u6309\u4e0b\u4ee5\u4e0b\u8bed\u6cd5\u7f16\u5199\uff0c\u7136\u540e\u901a\u8fc7svn commit\u90e8\u7f72\u5b8c\u6210\u5373\u53ef\u751f\u6548\u3002<br \/>\n<strong>\u8bed\u6cd5\u8bf4\u660e<\/strong><br \/>\nAppConfig\u7684\u8bed\u6cd5\u5206\u4e24\u79cd\uff0c\u4e00\u79cd\u662f\u7b80\u5355\u7684\u53c2\u6570\u7f57\u5217\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u7075\u6d3b\u7684\u8868\u8fbe\u5f0f\u8bed\u6cd5\uff0c\u4e0d\u540c\u7684\u529f\u80fd\u4f1a\u7528\u5230\u4e0d\u540c\u7684\u7c7b\u578b\u7684\u8bed\u6cd5\u3002<br \/>\n\u53c2\u6570\u65b9\u5f0f<br \/>\n\u76ee\u5f55\u9ed8\u8ba4\u9875\u9762<br \/>\n&#8211; directoryindex: file_list<br \/>\nfile_list \u4e2d\u5404\u4e2a\u6587\u4ef6\u540d\u4ee5\u7a7a\u683c\u5206\u9694\uff0cdirectoryindex\u5728 yaml \u6587\u4ef6\u4e2d\u4ec5\u6709\u4e00\u9879<br \/>\n\u4f8b\u5b50\uff1a<br \/>\n&#8211; directoryindex: aaa.php bbb.html<br \/>\n\u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762<br \/>\n&#8211; errordoc: httpcode error_file<br \/>\nhttpcode \u662f\u8bf8\u5982404\u3001302\u4e4b\u7c7b\u7684http\u54cd\u5e94\u7801\uff0cerror_file\u662f\u670d\u52a1\u5668\u4ee5 httpcode\u54cd\u5e94\u8bf7\u6c42\u65f6\u54cd\u5e94\u7684\u6587\u4ef6\u3002errordoc\u5728yaml\u4e2d\u53ef\u4ee5\u914d\u7f6e\u591a\u9879\u3002<br \/>\n&#8211; errordoc: 404 \/path\/404.html<br \/>\n&#8211; errordoc: 403 \/path\/403.html<br \/>\n\u8868\u8fbe\u5f0f\u8bed\u6cd5<br \/>\n\u5176\u4ed6\u529f\u80fd\u9700\u8981\u7528\u5230\u8868\u8fbe\u5f0f\u8bed\u6cd5\uff0c\u5176\u5f62\u5f0f\u4e3a\uff1a<br \/>\nif (expression) do_something<br \/>\nexpression \u6709\u5982\u4e0b\u5f62\u5f0f\uff1a<br \/>\n1) in_header[&#8220;header_name&#8221;] op string_or_digit<br \/>\n2) out_header[&#8220;header_name&#8221;] op string_or_digit<br \/>\n3) path op string<br \/>\n4) query_string op string<br \/>\n5) is_file()<br \/>\n6) is_dir()<br \/>\n\u5173\u4e8e\u4ee5\u4e0a\u5f62\u5f0f\u8bf4\u660e\u5982\u4e0b\uff1a<br \/>\n1) in_header \u662f\u8bf7\u6c42\u5934\uff0cout_header \u662f\u54cd\u5e94\u5934\uff0cheader_name \u662f header \u7684\u540d\u5b57\uff0c\u5177\u4f53\u7684\u8bf7\u6c42\u5934\u548c\u54cd\u5e94\u5934\u53c2\u8003RFC\u5b98\u65b9\u6587\u6863<br \/>\n2) op \u662f\u64cd\u4f5c\u7b26\uff0c\u6709 ~\uff08\u6b63\u5219\u5339\u914d\uff09 !~\uff08\u6b63\u5219\u4e0d\u5339\u914d\uff09 ==\uff08\u76f8\u7b49\uff0c\u7528\u4e8e\u5b57\u7b26\u4e32\u548c\u6570\u5b57\uff09 !=\uff08\u4e0d\u76f8\u7b49\uff0c\u7528\u4e8e\u5b57\u7b26\u4e32\u548c\u6570\u5b57\uff09 &gt;, &gt;=, &lt;, &lt;=\uff08\u6bd4\u8f83\u64cd\u4f5c\u7b26\u4ec5\u7528\u4e8e\u6574\u5f62\u6570\u5b57\uff09<br \/>\n3) string \u662f\u5f62\u5982 &#8220;xxxx&#8221; \u7684\u5b57\u7b26\u4e32<br \/>\n4) string_or_digit \u8868\u793a string \u6216\u8005 digit\uff0c\u6839\u636e op \u7684\u79cd\u7c7b\uff0c\u540e\u9762\u8ddf string \u6216\u8005 digit<br \/>\n5) path \u662f\u7cfb\u7edf\u5b8f\uff0c\u8868\u793a\u7528\u6237\u8bf7\u6c42\u7684 url \u53bb\u6389\u4e3b\u673a\u90e8\u5206\u548c\u67e5\u8be2\u4e32\u540e\u5269\u4e0b\u7684\u90e8\u5206<br \/>\n6) query_string \u662f\u7cfb\u7edf\u5b8f\uff0c\u8868\u793a\u67e5\u8be2\u4e32\uff0c\u4e00\u822c\u662furl\u4e2d\u95ee\u53f7\u540e\u9762\u7684\u5185\u5bb9<br \/>\n7) is_file() \u548c is_dir \u662f\u7cfb\u7edf\u51fd\u6570\uff0c\u5224\u65ad path \u662f\u6587\u4ef6\u8fd8\u662f\u76ee\u5f55\uff0c!is_file()\uff0c!is_dir() \u5206\u522b\u662f\u5176\u5426\u5b9a\u5f62\u5f0f\u3002<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\u534e\u4e3d\u4e3d\u7684\u5206\u5272\u7ebf&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u6211\u5728\u65b0\u6d6aSAE\u4e0a\u642d\u5efa\u4e86\u4e00\u4e2ayourls\u7684\u7f51\u5740\u7f29\u77ed\u670d\u52a1\uff0c\u7531\u4e8e\u65b0\u6d6aSAE\u4e0d\u652f\u6301.htaccess\uff0c \u53ea\u80fd\u9760AppConfig\u670d\u52a1\u4e2d\u7684URL\u91cd\u5199\u529f\u80fd\u6765\u5b9e\u73b0\u3002<br \/>\n<strong>URL\u91cd\u5199\u00a0<\/strong><br \/>\n&#8211; rewrite: if (complex_express) goto target_url<br \/>\n\u5728 rewrite \u4e2d\uff0ccomplex_express \u53ef\u4ee5\u7528 &amp;&amp; \u8fde\u63a5\uff0c\u7ec4\u6210\u590d\u5408\u8868\u8fbe\u5f0f\u3002\u9664 out_header \uff08\u6ca1\u529e\u6cd5\u6839\u636e\u54cd\u5e94 header \u505a\u91cd\u5b9a\u5411\uff09 \u5916\u90fd\u53ef\u4ee5\u51fa\u73b0\u5728 rewrite \u7684 if \u4e2d\uff0c\u5e76\u4e14 path \u53ea\u80fd\u51fa\u73b0\u4e00\u4e2a\uff08\u5982\u679c\u6709\u591a\u4e2a\uff0c\u53ea\u6709\u6700\u540e\u4e00\u4e2a\u751f\u6548\uff0c\u5176\u5b83\u88ab\u5ffd\u7565\uff09\uff0c\u5f53\u7701\u7565 path \u65f6\uff0c\u8868\u793a\u4efb\u610f\u8bf7\u6c42\u3002<br \/>\ntarget_url \u8868\u793a\u91cd\u5b9a\u5411\u7684\u76ee\u6807url\uff0c\u5728target_url \u53ef\u4ee5\u4ee5 $N \u7684\u5f62\u5f0f\u8868\u793a path \u4e2d\u5339\u914d\u5230\u7684\u5185\u5bb9\uff0c%N \u7684\u5f62\u5f0f\u8868\u793a\u6700\u540e\u4e00\u4e2aquery_string \u4e2d\u5339\u914d\u5230\u7684\u5185\u5bb9\uff0c\u56e0\u4e3aquery_string \u53ef\u4ee5\u5728 if \u4e2d\u51fa\u73b0\u591a\u6b21\uff0c\u4ee5%{QUERY_STRING} \u8868\u793a\u67e5\u8be2\u4e32\u3002<br \/>\n\u4f8b\u5982\uff1a<br \/>\n&#8211; rewrite: if(query_string ~ &#8220;^(so)$&#8221; &amp;&amp; path ~ &#8220;zhaochou$&#8221;) goto &#8220;\/url\/%1&#8221;<br \/>\n&#8211; rewrite: if(is_dir( ) &amp;&amp; path ~ &#8220;urldir\/(.*)&#8221;) goto &#8220;\/url\/$1&#8221;<br \/>\n&#8211; rewrite: if( !is_file() &amp;&amp; !is_dir()) goto &#8220;index.php?%{QUERY_STRING}&#8221;<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\u534e\u4e3d\u4e3d\u7684\u5206\u5272\u7ebf&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u6bd4\u8f83\u5b89\u88c5\u81ea\u52a8\u751f\u6210\u7684.htaccess\u89c4\u5219<br \/>\n# BEGIN YOURLS<br \/>\n&lt;IfModule mod_rewrite.c&gt;<br \/>\nRewriteEngine On<br \/>\nRewriteBase \/<br \/>\nRewriteCond %{REQUEST_FILENAME} !-f<br \/>\nRewriteCond %{REQUEST_FILENAME} !-d<br \/>\nRewriteRule ^(.*)$ \/yourls-loader.php [L]<br \/>\n&lt;\/IfModule&gt;<br \/>\n# END YOURLS<br \/>\n\u6700\u7ec8\u6211\u5728Appconfig\u4e2d\u7684\u914d\u7f6e\u4e3a<br \/>\n&#8211; rewrite: if( !is_file() &amp;&amp; !is_dir() &amp;&amp; path ~ &#8220;^(.*)$&#8221; ) goto &#8220;\/yourls-loader.php&#8221;<br \/>\n<strong>\u5907\u6ce8\u548c\u8bf4\u660e<\/strong><br \/>\n\u66f4\u591a\u9875\u9762\u91cd\u5b9a\u5411\u4f8b\u5b50\uff1a<br \/>\n\u5f53 url \u5339\u914d urldir\/(.*) \uff0c\u5e76\u4e14 \u8f93\u5165 header referer \u7b49\u4e8e sina \u65f6\uff0c\u8df3\u8f6c\u81f3\u9875\u9762 \/usr\/$1\uff0c$1 \u8868\u793a\u521a\u521a\u5339\u914d\u7684 urldir\/(.*) \u4e2d\u7684 (.*) \u90e8\u5206\u3002<br \/>\n&#8211; rewrite: if (path ~ &#8220;urldir\/(.*)&#8221; &amp;&amp; in_header[&#8220;referer&#8221;] == &#8220;sina&#8221;) goto &#8220;\/url\/$1&#8221;<br \/>\n\u5f53 url \u5339\u914d urldir\/(.*)\uff0c\u5e76\u4e14\u8bf7\u6c42\u7684\u662f\u4e00\u4e2a\u76ee\u5f55\u65f6\uff0c\u8df3\u8f6c\u81f3 \/url\/$1<br \/>\n&#8211; rewrite: if(is_dir( ) &amp;&amp; path ~ &#8220;urldir\/(.*)&#8221;) goto &#8220;\/url\/$1&#8221;<br \/>\n\u5f53 url \u5339\u914d path\uff0c\u5e76\u4e14\u8bf7\u6c42\u7684\u4e0d\u662f\u4e00\u4e2a\u6587\u4ef6\u65f6\uff0c\u8df3\u8f6c\u81f3 \/url\/query.php<br \/>\n&#8211; rewrite: if(! is_file() &amp;&amp; path ~ &#8220;path&#8221;) goto &#8220;\/url\/query.php&#8221;<br \/>\n\u5f53\u67e5\u8be2\u4e32\u7b49\u4e8eso\uff0c\u5e76\u4e14 url \u4ee5 zhaochou \u7ed3\u5c3e\u65f6\uff0c\u8df3\u8f6c\u81f3 \/url\/%1\uff0c%1 \u8868\u793a query_string \u5339\u914d\u5230\u7684\u90e8\u5206\u3002<br \/>\n&#8211; rewrite: if(query_string ~ &#8220;^(so)$&#8221; &amp;&amp; path ~ &#8220;zhaochou$&#8221;) goto &#8220;\/url\/%1&#8221;<br \/>\n\u5f53\u67e5\u8be2\u4e32\u4e0d\u5305\u542bsohu\uff0c\u5e76\u4e14 url \u4ee5 zhaochou \u7ed3\u5c3e\u65f6\uff0c\u8df3\u8f6c\u81f3 \/url\/query.php?%{QUERY_STRING}\uff0c%{QUERY_STRING} \u8868\u793a\u67e5\u8be2\u4e32\u3002<br \/>\n&#8211; rewrite: if(query_string !~ &#8220;sohu&#8221; &amp;&amp; path ~ &#8220;zhaochou$&#8221;) goto &#8220;\/url\/query.php?${QUERY_STRING}&#8221;<br \/>\n\u5982\u679c url \u65e2\u4e0d\u662f\u6587\u4ef6\uff0c\u4e5f\u4e0d\u662f\u76ee\u5f55\uff0c\u8df3\u8f6c\u81f3 index.php?%{QUERY_STRING}<br \/>\n&#8211; rewrite: if( !is_file() &amp;&amp; !is_dir()) goto &#8220;index.php?%{QUERY_STRING}&#8221;<br \/>\n<strong>\u3010FAQ\u3011<\/strong>:<\/p>\n<p>1. \u5982\u679c\u6709\u5f62\u5982 path ~ &#8220;^(.*)$&#8221; \u7c7b\u7684\u8bf7\u6c42\uff0c\u4e00\u5b9a\u8981\u52a0\u4e0a is_file \u6216 is_dir \u4e4b\u7c7b\u7684\u5224\u65ad\uff0c\u9632\u6b62\u65e0\u7a77\u7684rewrite\u3002<br \/>\n2. path \u662f\u7528\u6237\u8bf7\u6c42\u7684\u8d44\u6e90\u8def\u5f84\uff0c\u6bd4\u5982\u8bf7\u6c42 http:\/\/x.sinaapp.com\/b\/index.php?a=4\uff0c\u90a3\u4e48path\u5c31\u662f \/b\/index.php\u3002<br \/>\n3. \u5728goto\u8bed\u53e5\u4e2d\uff0c\u867d\u7136\u67d0\u4e9b\u65f6\u5019\u53ef\u4ee5\u4e0d\u4ee5\/\u5f00\u5934\uff0c\u4f46\u662f\u5f3a\u70c8\u5efa\u8bae\u4ee5\/\u5f00\u5934\u3002<\/p>\n<p><strong>\u7b2c\u4e09\u65b9\u5de5\u5177<\/strong><br \/>\n\u7b2c\u4e09\u65b9\u5f00\u53d1\u7684\u751f\u6210AppConfig\u7684\u5c0f\u5de5\u5177 http:\/\/saetools.sinaapp.com\/appconfig.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u670d\u52a1\u6982\u8981 AppConfig\u670d\u52a1\u662fSAE\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u7684\u5bf9web\u670d\u52a1\u5668\u8fdb\u884c\u81ea\u5b9a\u4e49\u914d\u7f6e\u7684\u529f\u80fd\uff0c\u4f7f\u7528AppConfi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-627","post","type-post","status-publish","format-standard","hentry","category-website"],"_links":{"self":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=627"}],"version-history":[{"count":0,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/627\/revisions"}],"wp:attachment":[{"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}