E
E
Evgeny Shiryaev2015-02-27 12:36:18
htaccess
Evgeny Shiryaev, 2015-02-27 12:36:18

Redirects from http to https?

Hi everybody. Problem following, the certificate on a site is bought. You need to configure the correct redirect from http to https. At the moment, the code is registered in .htaccess:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I work all
site.ru redirects to https://www.site.ru
www.site.ru to https://www.site.ru

except:

https://site.ru to https://www.site.ru (Certificate error).

I read on the forums, someone writes that you need to separately purchase a certificate for https://site.ru , this is of course nonsense and not an option. The hoster wrote that you first need to do a simple redirect from http//site.ru to http:/www.site.ru , then connect https. Tried a bunch of methods, nothing helped. I would really appreciate your help, thanks!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Shiryaev, 2015-03-02
@Jekis

#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) http://%{HTTP_HOST}:443/$1 [L,R]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

S
ShamblerR, 2015-02-27
@ShamblerR

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) http://%{HTTP_HOST}:443/$1 [L,R]

P
pikla, 2017-02-14
@pikla

#Redirect from www to non-www(https)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
#Redirect from http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Here is a working version

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question