Think before you speak, read before you think.

nginx rewrite规则|静态目录重写

静态目录重写

location /static/ {
root /var/www/application/blog;
if (-f $request_filename) {
rewrite ^/static/(.*)$  /static/$1 break;
}

判断文件或目录是否存在,不存在返回到首页

if (!-e $request_filename) {
 #rewrite ^/(.*)$ /blog/index.php last;
 #表示完成rewrite,url不变,而permanent是301重定向,会跳到主页url
 rewrite ^/(.*)$ /blog/index.php permanent;
 }

禁止直接访问uploads目录

location ~ ^/blog/wp-content/uploads/ {
        deny all;
        break;
}

图片防盗链

location ~* \.(gif|jpg|jpeg)$ {
valid_referers none blocked www.jpuyy.com jpuyy.com;
if ($invalid_referer) {
rewrite ^/(.*) http://www.jpuyy.com;
}
}

302跳转HTTP/1.1 302 Moved Temporarily

 rewrite ^/$ http://2014.jpuyy.com redirect; 

301跳转HTTP/1.1 301 Moved Permanently

 rewrite ^/2014/?$ /abc/index.php permanent;

:)EOT


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *