W
W
www_kot_www2019-07-11 15:35:42
URL Handling
www_kot_www, 2019-07-11 15:35:42

How to redirect all pages from https to http index.php?

Help set up a redirect in htaccess.
It is necessary that all transitions to pages with or without www using the https protocol redirect
to the index page www.site.ru/index.php
there are many manuals on how to switch from http to https - but I can’t do the opposite and catch everyone. Please help set up. Honestly, I've been struggling with this for 3 hours now. Any new rule cancels the previous one and I can not understand anything. Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
www_kot_www, 2019-07-11
@www_kot_www

This solution helped. Maybe someone else was looking for this answer. I leave the code
RewriteEngine On
RewriteCond %{SERVER_PORT} ^443$ [OR]
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ site.ru/index.php [R=301,L]

V
Viktor Taran, 2019-07-11
@shambler81

Do not forget that the https certificate must still exist, because otherwise the redirect will not work.

############################################################################
#### Выбор основного зеркала (с 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 если он включен.

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question