SSL CertificatesTrust solutions
15.00$ Basic Quick-Scan
  • OWASP Top 10 Scanning
  • Multi Page Web Applications
  • REST API & JavaScript Scan
  • Set it up in minutes
44.00$ Starting at
  • Protect up to 250 domains
  • Wildcard domains
  • Single and sub-domains
  • Public IP addresses
49.00$ Billed annually
  • Registered companies
  • Non Profit, Funds and Trusts
  • Government entities
  • Sole Proprietors/Individuals
Home Wiki Installation manuals How to Redirect HTTP to HTTPS in Nginx & Apache?

How to Redirect HTTP to HTTPS in Nginx & Apache?

  • In order to change the URL of the page displayed in the search results, Google recommends using 301 Redirect. This is the best way to make sure that search engines and users will be directed to the correct page, and also protect themselves from losing traffic from search engines.

    • 1

      In what cases is it worth using a 301 redirect?

      • If there are several identical versions on different subdomains or folders, for example, or http://site.tld or httpS://, to redirect the visitor to the main version of the site.
      • Due to rebranding (or for other reasons), when you want users to not notice the difference when they click on the same URL. When gluing (combining) two sites so that links from all pages of the first redirect to a new one.
    • 2

      How to configure 301 Redirect from HTTP to HTTPS in Apache

      Normally, there are at least two virtual hosts in use when you are using an SSL certificate. Ordinary server requests should be served by port 80, and SSL requests served by port 443. Use ordinary redirect directive in you wish to redirect users from non-SSL to SSL site. In order to enable redirection using Apache, you must enable mod_rewrite:

      LoadModule rewrite_module /usr/lib/apache2/modules/

      For the changes to take effect, you reboot the Apache web server:

      apache2ctl restart

      In .htaccess to redirect from HTTP to HTTPS add:

      <VirtualHost *:80>
          RewriteEngine On
          RewriteCond %{SERVER_PORT} !^443$
          RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

      Save and close the file, then restart the HTTP sever using next command:

      $ sudo systemctl restart apache2 [Ubuntu/Debian]
      $ sudo systemctl restart httpd [RHEL/CentOS]

      One page redirect, instead entire website

      <VirtualHost *:80>
          RewriteEngine On
          RewriteRule ^apache-redirect-http-to-https.html$ https://www.domain.tld/apache-redirect-http-to-https.html [R=301,L]

      Hints about .htaaccess redirects

      • Do not duplicate RewriteEngine On;
      • The RewriteCond and RewriteRule must immediately follow the RewriteEngin on/
    • 3

      NGNIX redirect from HTTP to HTTPS

      Use this tutorial to redirect all your visitors to HTTPS with WWW domain prefix using. That method uses 301 redirect techniques and is safe for SEO according to Google best practices. You will need to edit the Nginx virtual host configuration file to forcefully redirect all users to HTTPS://www.domain.tld using the described example below.

      # Force all users to https://www.domain.tld
      server {
          listen 80;
          server_name domain.tld www.domain.tld;
          return 301 https://www.domain.tld$request_uri;
      server {
          listen 443 ssl;
          server_name domain.tld;
          ssl_certificate /etc/nginx/ssl/www.domain.tld.pem;
          ssl_certificate_key /etc/nginx/ssl/www.domain.tld.key;
          return 301 https://www.domain.tld$request_uri;
      server {
          listen 443 ssl;
          server_name www.domain.tld;
          root /var/www/html
          error_page 403 /error/404.html;
          error_page 404 /error/404.html;
          error_page 500 502 503 504 /error/50x.html;
          ssl_certificate /etc/nginx/ssl/www.domain.tld.pem;
          ssl_certificate_key /etc/nginx/ssl/www.domain.tld.key;

      Restart the Nginx web server to put the changes into effect using the command:

      sudo systemctl restart Nginx
    • Conclusion

      Today it is mandatory to use the HTTPS protocol to protect all the traffic between your website visitors and the server. We suggest Nginx web server as the most powerful and simplest way to set up your website with permanent 301 redirects.

Fast Issuance within 3-5 minutes

Get a Domain Validation SSL certificate within just 5 minutes using our friendly and automated system. No paperwork, callback or company required.

Price Match 100% Guarantee

Found a better price? We will match it - guaranteed. Get the best possible price in the World with us. The correct place to save your money.

Free SSL 90-day for free

Try 90-day Trial SSL Certificate before the real purchase to test cert's functionality. 99.9% browser and mobile support. Free reissues.

Money Back 30-day guarantee

Customer satisfaction is our major concern. Get a full refund within 30 days for any purchase of SSL certificates with 100% guarantee.

Speed up SSL issuance

GoGetSSL® offers fastest issuance of SSL due to use of LEI code and API automation. Legal Entity Identifier (LEI) is a global identity code, just like DUNS. Learn how LEI works.

1,422,468+Total LEIs issued
224+Jurisdictions supported