nginx支持if语法,语法和平常的代码格式差不多:
1.当访问的文件和目录不存在时,重定向到某个html文件
if( !-e $request_filename )
{
rewrite ^/(.*)$ index.html last;
}
#这个不会自动index.html
if (-e $document_root/static$request_uri) {
rewrite ^/(.*)$ /static/$1 break;
break;
}
#这个会自动index.html
if (-e "${document_root}/static${uri}") {
rewrite ^/(.*)$ /static/$uri break;
}
if (-e $request_filename) {
break;
}
#这个设置index
set $static "/static";
try_files $static$uri $static$uri/index.html /index.php;