P
P
pesice43892021-01-25 15:27:00
htaccess
pesice4389, 2021-01-25 15:27:00

How to redirect from http and www to https without www?

Hello!
Tell me how to make such a redirect for all pages of the site

http:// --> https://
http://www --> https://
https://www --> https://

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Minister of Defense, 2021-01-25
@pesice4389

RewriteEngine on
RewriteCond %{HTTPS}_%{HTTP_HOST} ^(?|off_(?:www\.)?(.*)|on_www\.(.*)) [NC]
RewriteRule .* https://%1/$0 [R=301,L]

V
Vladislav Lyskov, 2021-01-25
@Vlatqa

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

V
Viktor Taran, 2021-01-25
@shambler81

everything can be done separately since there is no need to combine fish and meatballs, all search engines understand the sequence of redirects and this does not affect SEO

RewriteEngine On
   #  Директива включает редиректы.
RewriteBase / 
# Без директивы (.*) = /$1 будет /var/wwww/site/web/$1  с директивой  = /$1

#  Удалить www
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
 # Проверяем, содержит ли домен www в начале URL.
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    # Перенаправляем удаляем www

# https
RewriteCond %{HTTPS} off
   # Проверяем наличие https в URL.
RewriteCond %{REQUEST_URI} !^/bitrix/admin/1c_exchange\.php$ [NC] 
   #  Исключим обмен с 1С, ему требуется только 200 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
   # Перенаправляем протокол на http.

From the subtleties, depending on the web server and the correctness of its settings, the https redirect may not work or lead to a cycle, in which case you need to choose the one that suits you.
How to set up a redirect to https in .htaccess?
If it didn’t help, then the reason for the loop can be found here
https://bertal.ru/index.php?a566754
if the reason https://site.ru:80is, then write down the place %{HTTP_HOST} domain name.
If you do not have Bitrix then
RewriteCond %{REQUEST_URI} !^/bitrix/admin/1c_exchange\.php$ [NC]
can be deleted

D
dankoivan, 2021-01-26
@dankoivan

A good instruction on how to set up and use Redirect 301 and 302 is described in the article https://hostiq.ua/wiki/301-redirect/#six

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question