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:
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:
-
Use the Nginx redirect function, add
return 301 https://$host$request_uri;in the HTTPserverblock to redirectHTTPrequests toHTTPS. Modify the content as follows:server {
listen 80;
#Redirect HTTP domain requests to HTTPS
return 301 https://$host$request_uri;
} -
Restart the Nginx server, then you can visit the domain name and achieve automatic redirection from
HTTPtoHTTPS.
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:
-
Edit the
web.xmlfile in the/usr/tomcat9.0.13/confdirectory and locate the</welcome-file-list>tag. -
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> -
Edit the
server.xmlfile in the/usr/tomcat9.0.13/confdirectory, and change theredirectPortparameter to the SSL port ofconnector, which is port 443. As shown below:<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" /> -
Save the configuration file, then run the following command in the
bindirectory to verify whether the configuration is correct../configtest.sh -
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
For the complete SSL certificate installation process, please refer to Tomcat Server sslTrus SSL Certificate Installation Tutorial
IIS
-
Open the IIS Service Manager.
-
Select the site name under Websites, then double-click to open "URL Rewrite". As shown in the image below:
NotePlease download and install the URL Rewrite module before performing this step.

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

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

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

- 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.
-
Click Apply in the right "Actions" pane to save.
-
Return to the website homepage, then click Restart in the right "Manage Website" pane. After that, you can access the site via HTTPS.
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:
-
Edit the
httpd.confconfiguration file in the/etc/httpd/confdirectory. Check whetherLoadModule rewrite_module modules/mod_rewrite.soexists in this configuration file. If it exists, remove the comment symbol (#) at the beginning of the line; if it does not exist, add the lineLoadModule rewrite_module modules/mod_rewrite.so, then save the configuration file. -
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> -
Restart the Apache server to access via your domain name, which will automatically redirect HTTP to HTTPS.
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:
-
Enter
a2enmod rewritein the command line to enable the redirect module. -
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> -
Restart the Apache server to access via your domain name, which will automatically redirect HTTP to HTTPS.
For the complete SSL certificate installation process, refer to sslTrus SSL Certificate Installation Tutorial for Apache2 Server