I
I
idsergey_alexandrov2017-08-25 10:41:17
htaccess
idsergey_alexandrov, 2017-08-25 10:41:17

Redirect from www to non-www in https conditions with one certificate?

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

Here is the code he redirects from www to without www , but only redirects normally on the main page on the rest redirects to this link https://site.ru/bitrix/urlrewrite.php
Is it possible to make the redirect pass normally without buying the 2nd certificate?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2017-08-25
@idsergey_alexandrov

1 your redirects must be before the CNC
2. Here is an example for you in which the links themselves will choose http or https, depending on where they came from.
Well, yes, everything works fine with Bitrix.
And the redirect to transfer to the mirror with https is placed in a separate rule.

############################################################################
#### Выбор основного зеркала (с www или без www)                        ####
############################################################################
    # 1. Удалить www
RewriteCond %{ENV:HTTPS} on
    #Если включен https
RewriteRule .* - [E=SSL:s]
    #То создаем переменную  ssl с текстом s
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
    # Проверяем, содержит ли домен www в начале URL.
RewriteRule ^(.*)$ http%{ENV:SSL}://%1/$1 [R=301,L]
    # Перенаправляем удаляем www

    # 2. Добавить www
#RewriteCond %{ENV:HTTPS} on
    #Если включен https
#RewriteRule .* - [E=SSL:s]
    #То создаем переменную  ssl с текстом s
#RewriteCond %{HTTP_HOST} !^www\.(.*) [NC]
    # Если нет www в начале домена
#RewriteRule ^(.*)$ http%{ENV:SSL}://www.%{HTTP_HOST}/$1 [R=301,L]
    #Подставляем www и https если он включен.

Well, the redirect itself to https
############################################################################
#### Перенаправляем протокол https на http                              ####
############################################################################
#RewriteCond %{ENV:HTTPS} on
   # Проверяем наличие https в URL.
#RewriteRule ^.*$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
   # Перенаправляем протокол на http.

############################################################################
#### Перенаправляем протокол http на https                              ####
############################################################################
#RewriteCond %{ENV:HTTPS} !on
   # Проверяем наличие https в URL.
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
   # Перенаправляем протокол на http.

I also recommend a couple more rules useful for Bitrix
https://klondike-studio.ru/standards/standartnyy-h...

K
kmg4e, 2017-08-25
@kmg4e

Make www without a certificate.
If it still redirects you, then why is there https

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question