使用wp super cache后移动端访问网站时无法直接请求index-https-mobile.html文件的原因

Home Forums Share your experiences / 经验分享 使用wp super cache后移动端访问网站时无法直接请求index-https-mobile.html文件的原因

This topic contains 0 replies, has 1 voice, and was last updated by  Sarah 2 weeks, 1 day ago.

  • Author
    Posts

  • Moderator
    #1 Sarah #289850

    这里只讲nginx版的配置。
    在wordpress官方网站所提供的wp super cache nginx配置中对于Mobile端请求是null cache的
    https://codex.wordpress.org/Nginx

    对其稍作修改就可以实现当mobile端请求网站时自动定位到mobile的html静态文件上

    1, 将从#START MOBILE 到#END MOBILE处的代码取消注释,如下

    # START MOBILE
      set $is_mobile '';
      # Mobile browsers section to server them non-cached version. COMMENTED by default as most modern wordpress themes including twenty-eleven are responsive. Uncomment config lines in this section if you want to use a plugin like WP-Touch
      if ($http_x_wap_profile) {
              set $is_mobile '-mobile';
      }
      if ($http_profile) {
              set $is_mobile '-mobile';
      }
      if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)) {
             set $is_mobile '-mobile';
      }
      if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-)) {
            set $is_mobile '-mobile';
      }
      #END MOBILE

    2,Set cache file处修改如下:

    # Set the cache file
      set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index$is_mobile.html";
      if ($https ~* "on") {
        set $cachefile "/wp-content/cache/supercache/$http_host/$cache_uri/index-https$is_mobile.html";
      }

    这样即可实现PC端请求PC端的HTML,移动端请求移动端的HTML文件了

You must be logged in to reply to this topic.

Fonts by Google Fonts. 31 Queries in 0.193 seconds.