E
E
ESSES18682019-04-24 20:15:19
htaccess
ESSES1868, 2019-04-24 20:15:19

Redirect to HTTPS from WWW. How?

Hello, friends!

Installed an SSL certificate. Now we need a redirect to HTTPS://WWW

The following scheme worked without HTTPS:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^site.ru
RewriteRule (.*) www.site.ru/$1 [R=301,L]

Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Viktor Taran, 2019-04-25
@shambler81

Everything is quite simple and complicated at the same time, I vanguy
You have nginx + apache as a result, the smart uncle who did this did everything according to manas in which http is used on the backend (by the way, all manas on the Internet contain this error) as a result of which you will have an http referee or
site.ru:443 or https://site.ru:80
or something like that, as a result, cyclic redirects will occur.
Because the backend knows nothing about the existence of the front.
Here you can go in several ways
: 1. sort through different spellings of redirects, because there are a lot of them, some of them may work, some may not.
2. fix the bug.
3. you have another error and it is somewhere in the website code.
4. all htaccess to studio.
5. unbind the redirect for www from https in principle. partially described here https://klondike-studio.ru/standards/standartnyy-h...
6. https://www.bertal.ru/ here you will see what exactly is in the cycle

D
dodo512, 2019-04-24
@dodo512

RewriteEngine On

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.site.ru/$1 [R=301,L]

R
Roman Pantyukhin, 2019-04-24
@roamario

Add after RewriteEngine On
Option 1
RewriteCond %{HTTPS} =off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
Option 2
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https ://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Option 3
RewriteCond %{ENV:HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R =301]
Option 4
RewriteCond %{HTTP:X-HTTPS} !1
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question