如何仅向支持 SSL/TLS 加密的设备提供网站的 Https:// 版本(通过 Apache .htaccess)

How to serve the Https:// version of your site (via Apache .htaccess) ONLY to devices that support SSL/TLS encryption

我有一个 lite(即瘦身/轻量级),“feature phone" version of my primary website, online at https://fp.jamesandersonjr.com, and I went to test it on the oldest phone I could find, in my house, with at least wi-fi, an old LG 840G,才发现 phone 不支持https:// 协议!

所以,我的问题是,如何在 支持加密的设备 (SSL/TLS/HTTPS) 上强制使用 https:// 版本的网站,而phone 功能(如 LG840G)等设备是否会 'automatically' 和 'only' 提供 http:// 版本的网站?

如果能做到这一点就太棒了,我相信 Google 知道该怎么做。

我需要在我的 'root' Apache .htaccess 文件中执行此操作,因为我确信这是完成此类操作的最可行方法。

好的,所以我用这个页面测试了 LG-840G:http://fp.jamesandersonjr.com/php/user_agent_detector.php

事实证明,它使用的浏览器在用户代理字符串中带有 Obigo,所以我设计了这个 .htaccess 代码:

RewriteEngine On
RewriteOptions inherit
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} "!(obigo|palmos|webos)" [NC]
RewriteCond %{HTTPS} !on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_USER_AGENT} "(obigo|palmos|webos)" [NC]
RewriteCond %{HTTPS} on [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

它只能为旧版移动浏览器提供 http:(非安全)版本,不支持 https://。它 NOT 应该也适用于现代 'smart'-phone 浏览器。他们可以妥善处理 SSL/TLS/HTTP.

答案是弄清楚哪些浏览器通常太旧而无法正确支持 SSL/TLS/HTTPS,并且只有 Apache .htaccess 'weed-out' 那些特定的浏览器类型。其余浏览器将被迫使用https://。这是执行此操作的 .htaccess 代码:

RewriteEngine On
RewriteOptions inherit
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} "!(obigo|palmos|webos)" [NC]
RewriteCond %{HTTPS} !on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_USER_AGENT} "(obigo|palmos|webos)" [NC]
RewriteCond %{HTTPS} on [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

如果您发现任何其他浏览器一般、非常旧或通常有缺陷,请告诉我,以便我更新代码。