时间:2023-02-09 12:30:02 | 来源:建站知识
时间:2023-02-09 12:30:02 来源:建站知识
最近把网站的移动模板从WP Mobile X插件的模板改为了Accelerated Mobile Pages(amp),一方面是因为WP Mobile X的自定义程度没有AMP高,另一方面这样也能减少个插件。原链接:www.example.com/archives/123跳转到:www.example.com/archives/123/amp
第一次改nginx.conf只判断了ua是否为移动端,改好后发现移动端无法打开网页,查看url发现url后面被加了好多/amp/amp/amp/amp…… set $amp 0; if ( $http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT-)|(SonyEricsson)|(NEC-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC-)|(SED-)|(EMOL-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)" ) { set $amp "${amp}1"; } if ( $request_uri !~ "/amp") { set $amp "${amp}1"; } if ($amp = "011"){ rewrite ^/(.*) https://www.example.com/$1/amp redirect; }
这段代码加在网站的配置文件中server{}里就可以了。关键词:实例,改变