Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Redirects must be done on the server. What is your server? Nginx, Apache?
For Apache
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# http to https
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
# non-www to www via https
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/certs/*.domain.pem;
ssl_certificate_key /etc/ssl/private/*.domain.pem;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
# Main configuration
server {
listen 443 ssl http2 default_server; # http2 нужен если вы хотите использовать HTTP/2, иначе не нужно
listen [::]:443 ssl http2 default_server; # http2 нужен если вы хотите использовать HTTP/2, иначе не нужно
server_name www.example.com;
ssl_certificate /etc/ssl/certs/*.domain.pem;
ssl_certificate_key /etc/ssl/private/*.domain.pem;
# Остальная конфигурация
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question