首页 文章

.htaccess https 301重定向移动网站重定向

提问于
浏览
1

我正在尝试设置从我的网站的所有非https和www版本到https版本的permanet 301重定向,同时将所有移动流量重定向到位于子域的移动版本

阅读了几个教程后,我能够组装这个(有效):

RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} off               [OR]
RewriteCond %{HTTP_HOST} ^www\.(.+)$   [NC]
RewriteRule ^ https:// site here [R=301,L,NE]


RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)

RewriteRule ^ - [CO=mredir:0:https:// site here]

RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]


RewriteCond %{HTTP_HOST}          !^m\.

RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 


RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]


RewriteRule ^ https://m. site here [R,L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]

该脚本确实有效,但我遇到的问题是它创建了2个登陆页面重定向(http,www ---> https和https:// ---> https://m . ),这会减慢进程并对seo产生不良影响 .

有人能指出一个很好的解决方案,将所有移动流量重定向到https://m . 和其他所有https:// ...

我也尝试使用php标头来解决问题,但它会产生同样的问题

任何帮助是极大的赞赏!

谢谢!

1 回答

  • 0

    你的.htacces首先从http重定向到https . 然后重定向移动流量 . 这导致非https移动流量的两次重定向 .

    如果您首先执行移动重定向,则应该只为所有情况留下一个重定向 .

相关问题