V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
d754903977
V2EX  ›  问与答

WP Super Cache 缓存以后,首页加上 index.php 后缀仍然可以访问

  •  
  •   d754903977 · 2016-11-08 19:26:15 +08:00 · 989 次点击
    这是一个创建于 2741 天前的主题,其中的信息可能已经有所发展或是发生改变。
    nginx , WP Super Cache 缓存以后,首页加上 index.php 后缀仍然可以访问,为了开 Mod rewrite 用的以下规则,求大神解答..我看了不少开了 WP Super Cache 的博客也是这样。

    location / {
    # 如果请求的文件已存在,直接返回
    if (-f $request_filename) {
    break;
    }
    set $supercache_file '';
    set $supercache_uri $request_uri;
    set $supercache 1;
    set $ihttp_host '';

    if ($request_method = POST) {
    set $supercache 0;
    }

    # 仅在访问文章永久链接时使用静态文件,请求中带参数则不使用静态缓存
    set $qs 0;
    if ($query_string) {
    set $qs 1;
    }

    # 不过从 twitter, facebook, feedburner 链接点过来的,总是带参数,这些访问仍然可以使用静态文件
    if ($query_string ~* "^utm_source=([^&]+)&utm_medium([^&]+)&utm_campaign=([^&]+)(&utm_content=([^&]+))?$") {
    set $qs 0;
    set $supercache_uri $document_uri;
    }
    #deactivate on high load
    if ($qs = 1) {
    set $supercache 0;
    }
    # 针对已登录用户(发表过评论),可以不静态化。在访问量高峰时可注释掉
    if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
    set $supercache 0;
    }

    # 支持移动设备,访问移动版本的网页缓存
    if ($http_user_agent ~* '(iphone|ipod|aspen|incognito|webmate|android|dream|cupcake|froyo|blackberry9500|blackberry9520|blackberry9530|blackberry9550|blackberry 9800|webos|s8000|bada)') {
    set $ihttp_host '-mobile';
    }

    # 指定静态缓存文件的路径
    if ($supercache = 0) {
    set $supercache_uri '';
    }
    if ($supercache_uri ~ ^(.+)$) {
    set $supercache_file /wp-content/cache/supercache/$http_host$1/index${ihttp_host}.html;
    }

    # 只有当缓存文件存在时,才进行 rewrite
    if (-f $document_root$supercache_file) {
    #rewrite ^(.*)$ $supercache_file break;
    rewrite ^ $supercache_file last;
    }

    # 所有其他请求,转给 wordpress 处理
    if (!-e $request_filename) {
    rewrite . /index.php last;
    }
    1 条回复    2016-11-09 02:10:33 +08:00
    ryd994
        1
    ryd994  
       2016-11-09 02:10:33 +08:00 via Android
    if (-f $request_filename) {
    break;
    }
    没有然后了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   907 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:58 · PVG 05:58 · LAX 14:58 · JFK 17:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.