Migrating a site from http to https

Hello!

Received an SSL certificate. Now you need to change the protocol from http to https, which caused some difficulties:

  1. What to write in htaccess to make a redirect with (http://www.site.ru, https://www.site.ru and http://site.ru) on https://site.ru (I'm having trouble with regulars)?
  2. A couple of scripts are connected to the site, which can only be accessed via the http protocol. What should I do? Can is it somehow painless to attach scripts to an https site over http?
  3. Are there any disadvantages or problems when switching to https?
Author: Виталина, 2014-12-12

4 answers

With StackOverflow:

 RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

In addition, you can make redirects by the port number, for example:

 RewriteCond %{SERVER_PORT} ^80$
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

This will redirect all requests received on port 80 to HTTPS.

You can not insert HTTP scripts on an HTTPS site, this destroys all the security that you wanted to achieve. You go to HTTPS for this purpose?

The disadvantages or advantages of the transition depend directly on your project.

 2
Author: Get, 2017-08-07 12:24:02

The hoster sent this option, and everything worked:

RewriteCond %{HTTP_HOST} ^www\.site\.ru [NC,OR]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$ [NC]
RewriteRule ^(.*)$ https://site.ru/$1 [R=301,L]

But now there is another problem...
Before making a redirect with https://www.site.ru -> https://site.ru the certificate is checked, and since the certificate was issued for a domain without WWW, an error is issued...

 1
Author: makan, 2014-12-15 09:02:16

On WORDPRESS, it helped

RewriteCond %{ENV:HTTPS} !on
 RewriteRule ^(.*)$https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 0
Author: Попов Александр, 2016-08-08 08:49:40

If you use Nginx, it is better to use the return url_state code directive. Redirection is better performed at the location level, so that the files robots.txt and sitemap.xml remained available for search engines. Context with http:

server {
  listen 80;

  server_name domain.tld;
  server_name www.domain.tld;

  location ^/robots.txt {
    try_files $uri =404;
  }

  location ^/sitemap.xml {
    try_files $uri =404;
  }

  location / {
    return 301 https://www.domain.tld$request_uri;
  }
}

Within the http context, it is desirable to enable compression:

gzip on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss     text/javascript;
gzip_disable "msie6";

The article Nginx can also help you. Switching from http to https.

 0
Author: Alex, 2016-09-20 06:58:56