location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; break;
}
}
location ^~ /protected {
deny all;
}
location ~ ^/(Assets|Template)/ {
try_files $uri $uri/ /index.php?$request_uri;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {
expires 3d;
}
将以上规则写入站点 Nginx 配置的 server { } 内,然后执行 nginx -t 并重载。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?s=$1 [L]
RewriteRule ^protected/ - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Assets|Template)/.*$ /index.php?%{REQUEST_URI} [L,QSA]
</IfModule>
将以上规则写入网站根目录 .htaccess(需开启 mod_rewrite 并允许 Override)。