http://domain to https://www in one redirect

ぃ、小莉子 提交于 2019-12-23 05:56:04

问题


I am using a single domain certificate (only on the www. subdomain) and want to have all users using this.

Currently i have the following in my htaccess file:

## force HTTPS and www. if any of them are not already present
RewriteCond %{HTTP_HOST} (?!^www\.)^(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]

But the problem is, that this seems to lead to two separate redirects:

http://domain.com -> https://domain.com -> https://www.domain.com

This means 3 RTTs for the user until he reaches the correct page. In addition only the second redirect seems to be permanent, the first one (http to https) seems to be temporary,

Is there any solution which directly sends requests of from http to https+www?

Many thanks in advance!


回答1:


There's only one redirect. The target is https://www.%1. There is no redirect to http://www.%1 and no redirect to https://%1. Only https://www.%1.

No idea how you arrived at the conclusion that this rule caused 2 different redirects. Is this what your access logs are saying? Or the browser's network console?



来源:https://stackoverflow.com/questions/25092323/http-domain-to-https-www-in-one-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!