Wordpress 如何在手机上自动将我网站的每篇帖子重定向到AMP版本?
我想在手机上自动重定向我网站的每个帖子。我正在使用这个代码Wordpress 如何在手机上自动将我网站的每篇帖子重定向到AMP版本?,wordpress,.htaccess,redirect,amp-html,auto,Wordpress,.htaccess,Redirect,Amp Html,Auto,我想在手机上自动重定向我网站的每个帖子。我正在使用这个代码 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} !/amp$ [NC] RewriteCond %{HTTP_USER_AGENT} (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hipto
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/amp$ [NC]
RewriteCond %{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) [NC]
RewriteRule ^([a-zA-Z0-9-]+)([\/]*)$ example.x/$1/amp [L,R=302]
您可以使用javascript
如果设备不是桌面。重定向到Amp版本
<script>
var isMobile = window.orientation > -1;
if(isMobile){
window.location.replace("{{ url('aboutUsAMP') }}");
};
</script>
var isMobile=window.orientation>-1;
if(isMobile){
replace(“{url('aboutsump')}}”);
};
我必须在每页上使用自动重定向。通过这种方法,我将不得不在每个不适用的页面上手动执行。