Skip to main content

How to Redirect HTTP to HTTPS for a Website with an SSL Certificate Installed?

After completing certificate deployment, you need to configure a 301 forced redirect rule on the server to enforce HTTPS encrypted access across the entire site. The specific operation methods for each server are as follows:

Note

After configuration, please clear your browser cache for testing. It is recommended to use the Racent SSL Check Tool to verify the redirect status

Nginx

If you need to automatically redirect HTTP requests to HTTPS, you can configure it with the following steps:

  1. Use the Nginx redirect function, add return 301 https://$host$request_uri; in the HTTP server block to redirect HTTP requests to HTTPS. Modify the content as follows:

    server {
    listen 80;
    #Redirect HTTP domain requests to HTTPS
    return 301 https://$host$request_uri;
    }

  2. Restart the Nginx server, then you can visit the domain name and achieve automatic redirection from HTTP to HTTPS.

Note

For the complete SSL certificate installation process, please refer to Tutorial for Installing sslTrus SSL Certificate on Nginx Server


Tomcat

If you need to automatically redirect HTTP requests to HTTPS, you can configure it with the following steps:

  1. Edit the web.xml file in the /usr/tomcat9.0.13/conf directory and locate the </welcome-file-list> tag.

  2. Add a new line after the closing tag </welcome-file-list>, then insert the following content.

    <login-config>  
    <!-- Authorization setting for SSL -->
    <auth-method>CLIENT-CERT</auth-method>
    <realm-name>Client Cert Users-only Area</realm-name>
    </login-config>
    <security-constraint>
    <!-- Authorization setting for SSL -->
    <web-resource-collection >
    <web-resource-name >SSL</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    </security-constraint>
  3. Edit the server.xml file in the /usr/tomcat9.0.13/conf directory, and change the redirectPort parameter to the SSL port of connector, which is port 443. As shown below:

    <Connector port="80" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="443" />
  4. Save the configuration file, then run the following command in the bin directory to verify whether the configuration is correct.

    ./configtest.sh
  5. If there is no configuration issue, restart the Tomcat server to access your domain name and enable automatic redirection from HTTP to HTTPS.

    ./shutdown.sh  #Stop Tomcat server
    ./startup.sh #Start Tomcat server
Tip

For the complete SSL certificate installation process, please refer to Tomcat Server sslTrus SSL Certificate Installation Tutorial


IIS

  1. Open the IIS Service Manager.

  2. Select the site name under Websites, then double-click to open "URL Rewrite". As shown in the image below:

    Note

    Please download and install the URL Rewrite module before performing this step.

    IIS

  3. Go to the "URL Rewrite" page, and click Add Rule in the "Actions" pane on the right. As shown in the image below:

    IIS

  4. In the pop-up "Add Rule" window, select Blank Rule and click OK. As shown in the image below:

    IIS

  5. Go to the "Edit Inbound Rule" page. As shown in the image below:

    IIS

    • Name: Enter Http redirect to https.
    • Matches URL: Manually enter (.*) in the "Pattern" field.
    • Conditions:
      • Click Add, and the "Add Condition" window will pop up.
      • Condition input: {HTTPS}.
      • Check if input string: Keep the default selection Matches the pattern.
      • Pattern: Manually enter ^OFF$.
    • Actions: Fill in the following parameters.
      • Action type: Select Redirect.
      • Redirect URL: https://{HTTP_HOST}/{R:1}.
      • Redirect type: 301 Redirect.
  6. Click Apply in the right "Actions" pane to save.

  7. Return to the website homepage, then click Restart in the right "Manage Website" pane. After that, you can access the site via HTTPS.

Note

For the complete SSL certificate installation process, please refer to IIS Server sslTrus SSL Certificate Installation Tutorial


Apache

If you need to automatically redirect HTTP requests to HTTPS, you can configure it by following the steps below:

  1. Edit the httpd.conf configuration file in the /etc/httpd/conf directory. Check whether LoadModule rewrite_module modules/mod_rewrite.so exists in this configuration file. If it exists, remove the comment symbol (#) at the beginning of the line; if it does not exist, add the line LoadModule rewrite_module modules/mod_rewrite.so, then save the configuration file.

  2. Open the http.conf file and add the following content to the configuration file:

    <VirtualHost *:80>
    # Add new content
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
    </VirtualHost>
  3. Restart the Apache server to access via your domain name, which will automatically redirect HTTP to HTTPS.

Tip

For the complete SSL certificate installation process, refer to sslTrus SSL Certificate Installation Tutorial for Apache Server


Apache2

If you need to automatically redirect HTTP requests to HTTPS, you can configure it through the following steps:

  1. Enter a2enmod rewrite in the command line to enable the redirect module.

  2. Then open the HTTP configuration file, for example: /etc/apache2/sites-available/000-default.conf, and add the following content to the configuration file:

    <VirtualHost *:80>
    # Add new content
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
    </VirtualHost>
  3. Restart the Apache server to access via your domain name, which will automatically redirect HTTP to HTTPS.

Tip

For the complete SSL certificate installation process, refer to sslTrus SSL Certificate Installation Tutorial for Apache2 Server