当我访问我的网站https://example.com时,我的浏览器响应ERR_CONNECTION_REFUSED。请注意,以下各项工作:如何使用.htaccess将HTTPS非www重定向到HTTPS www?
- https://www.example.com
- http://example.com重定向到https://www.example.com
- http://www.example.com重定向到https://www.example.com
我如何可以重定向https://example.com请求https://www.example.com使用的.htaccess?
我已经试过这似乎并没有工作如下:
// .htaccess
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
我试过这个,但我认为它与httpd.conf中的现有规则冲突。只有当请求是“https:// example.com”时,是否有重定向到www的方法? – henrywright
如果原始URL是'http:// www.example.com',那么你不需要成为'https:// www.example.com'。顺便说一句,你可以在httpd.conf中使用这个规则,只记得重新启动Apache并清空浏览器缓存(或使用curl命令行进行测试) – anubhava
感谢您的建议@anubhava。 'http:// www.example.com'已经重定向到'https:// www.example.com'。它只是需要处理的'https:// example.com'到'https:// www.example.com'。 – henrywright