自用的wordpress/Nginx伪静态规则

我的收藏 Loading... 阅读

主要适用于纯静态插件 Super Static Cache 使用的伪静态规则,其中包括之前的死链接301到现在的链接。

如果死链接太多会影响网站的收录和用户的访问,使用下面的这个伪静态规则可以避免这一类的问题。

代码如下:

#BEGIN Super Static Cache
location / {
    
    if (-f $request_filename) {
        break;
    }
    if ($uri ~ /(.*)$){
        set $wpuri $1;
        set $sscfile $document_root/super-static-cache/$1;
    }
    set $ssc Y;
    if ($query_string !~ .*=.*){
        set $ssc "${ssc}Y";
    }
    if ($request_method != "POST"){
        set $ssc "${ssc}Y";
    }

    if (-f $sscfile){
        set $ssc "${ssc}F";
    }
    if (-f $sscfile/index.html){
        set $ssc "${ssc}I";
    }
   
    if ($ssc = YYYF){
        rewrite . /super-static-cache/$wpuri break;
    }
    if ($ssc = YYYI){
        rewrite . /super-static-cache/$wpuri/index.html break;
    }

    if (!-e $request_filename){
        rewrite  ^/(\d+).html  http://$host/post/$1.html permanent;
        rewrite  ^/html/(\d+).html  http://$host/post/$1.html permanent;
        rewrite  ^/(\d+)/  http://$host/post/$1.html permanent;
        rewrite . /index.php last;
    }
}
#End Super Static Cache

PS:想给网站搬家到虚拟主机上,一般虚拟主机使用的都是apache,所以这个规则就失效了,但我还是想复制备份一下,后面想用又得重新写,太浪费时间了。

Tags:

版权声明:若无特殊注明,本文皆为《书蓝画青》原创,转载务必保留文章来源。

本文链接:自用的wordpress/Nginx伪静态规则 & https://boke.slhq.cn/1948.html

推荐阅读
分享