Answer the question
In order to leave comments, you need to log in
Mod_rewrite How to redirect from http to https and site.com to www.site.com?
How to redirect from http to https and site.com to www.site.com?
This is how I translate to https, it works.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} !^www.site.com$ [NC]
RewriteRule ^(.*)$ https://www.site.com/$1 [L,R=301]
<?
get_headers('https://www.site.com')
<?
get_headers('https://site.com')
Answer the question
In order to leave comments, you need to log in
# 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 если он включен.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question