happylty
V2EX  ›  问与答

这个 301 重定向怎么弄?

  •  
  •   happylty · Feb 27, 2018 · 2280 views
    This topic created in 3016 days ago, the information mentioned may be changed or developed.
    自己弄了个博客,注册了七牛存储
    我想把 http://www.yunbeta.cn/wp-content/uploads/2018/02/XXXXX.jpg
    换成 http://niu.yunbeta.cn/wp-content/uploads/2018/02/XXXXX.jpg
    如何写这个规则。。
    新手入门,不太懂,望大神指导。
    9 replies    2018-03-07 21:07:38 +08:00
    huihuimoe
        1
    huihuimoe  
       Feb 28, 2018 via Android
    xiaopc
        2
    xiaopc  
       Feb 28, 2018 via Android
    有个非官方的七牛 WP 插件
    https://wordpress.org/plugins/wpjam-qiniu/
    301 过去不太好 /t/362493
    galvinwang007
        3
    galvinwang007  
       Feb 28, 2018
    可以参考这个插件的实现
    https://wordpress.org/plugins/wpjam-qiniu/
    happylty
        4
    happylty  
    OP
       Feb 28, 2018
    @huihuimoe
    @galvinwang007 我设置的是纯静态,这俩不管用了。。。
    @xiaopc 那个帖子也没解决啊
    xiaopc
        5
    xiaopc  
       Feb 28, 2018 via Android
    @happylty 他那个 conf 是能 301 跳转的,他说没解决是 HTML 里的图片地址直接换成 CDN 的地址,那个要用 sub_filter
    话说 WP 纯静态干嘛,不是生成 cache 就行了吗
    happylty
        6
    happylty  
    OP
       Feb 28, 2018
    @xiaopc 我试了试好像没用。。。
    纯静态比非纯静态快了 1 秒呢
    xiaopc
        7
    xiaopc  
       Feb 28, 2018 via Android
    @happylty 贴一下 conf 全部内容呢
    happylty
        8
    happylty  
    OP
       Mar 7, 2018
    @xiaopc #真静态 BEGIN Super Static Cache
    location / {
    #ngx_http_gzip_static_module and ngx_http_gunzip_module Must Be Added To Nginx
    gzip_static always;
    gunzip on;

    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.gz){
    set $ssc "${ssc}F";
    }
    if (-f $sscfile/index.html.gz){
    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 . /index.php last;
    }
    }
    #End Super Static Cache
    happylty
        9
    happylty  
    OP
       Mar 7, 2018
    @xiaopc 那个没用所以就删了,这个是 Super Static Cache 插件要求的。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5849 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 01:44 · PVG 09:44 · LAX 18:44 · JFK 21:44
    ♥ Do have faith in what you're doing.