【问题标题】:.htaccess https 301 redirect + mobile site redirect.htaccess https 301 重定向 + 移动网站重定向
【发布时间】:2017-09-21 23:52:28
【问题描述】:

我正在尝试设置从我网站的所有非 https 和 www 版本到 https 版本的永久 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 headers 来解决这个问题,但它会产生同样的问题

非常感谢任何帮助!

谢谢!

【问题讨论】:

    标签: .htaccess redirect mobile https


    【解决方案1】:

    您的 .htacces 首先从 http 重定向到 https。然后对移动流量进行重定向。这会导致非 https 移动流量的两次重定向。

    如果您先进行移动重定向,则在所有情况下都应该只留下一个重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 2014-09-08
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多