Skip to main content
All CollectionsDomains, Web Servers, and BeyondSSL
Redirecting HTTP to HTTPS: A Step-by-Step Guide
Redirecting HTTP to HTTPS: A Step-by-Step Guide
Rapyd Team avatar
Written by Rapyd Team
Updated over a week ago

This technical documentation provides a step-by-step guide on how to redirect HTTP traffic to HTTPS. By redirecting HTTP requests to the more secure HTTPS protocol, you can enhance the security of your web applications and protect sensitive information exchanged between clients and servers.

This guide assumes a basic understanding of web server configuration and is intended for system administrators or developers responsible for managing web server settings.


Before proceeding with the redirect configuration, ensure that the following prerequisites are met:

  1. A functioning web server (e.g., Apache, Nginx) that supports SSL/TLS and HTTPS connections.

  2. A valid SSL/TLS certificate is installed on the web server for the desired domain.

Step 1: Backup Configuration Files

Before making any changes, it is essential to create backups of the configuration files you will be modifying. This step ensures that you can revert to the previous configuration if any issues arise.

Step 2: Update Web Server Configuration

  1. Access the configuration file specific to your web server. The file may be located in different paths depending on the server software used:

    • Apache: /etc/apache2/sites-available/default-ssl.conf

    • Nginx: /etc/nginx/sites-available/default

  2. Open the configuration file using a text editor with administrative privileges.

  3. Locate the virtual host block for the domain you wish to redirect from HTTP to HTTPS. This block typically starts with the ‘VirtualHost’ directive in Apache or the ‘server’ block in Nginx.

  4. Add the following lines within the appropriate virtual host block:

# Apache Configuration
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Nginx Configuration
server {
listen 80;
return 301 https://$host$request_uri; }

5. Replace with your domain name.

6. Save the configuration file and exit the text editor.

Step 3: Test Configuration and Restart Server

  1. Test the configuration file for syntax errors to ensure it is valid.

    • Apache: Run the command ‘apachectl configtest’.

    • Nginx: Run the command ‘nginx -t’.

If any errors are detected, review the configuration file for typos or incorrect syntax.

2. If the configuration file passes the syntax test, restart the webserver to apply the changes.

  • Apache: Run the command ‘systemctl restart apache2’.

  • Nginx: Run the command ‘systemctl restart nginx’.

Step 4: Verify Redirect

  1. Open a web browser and enter the URL of your website using the http://

  2. protocol (e.g.,

  3. The browser should automatically redirect to the HTTPS version of your website (e.g., ‘’).

  4. Verify that the SSL/TLS certificate is valid and the website is functioning correctly over HTTPS.


By following this step-by-step guide, you will have successfully configured your web server to redirect HTTP traffic to HTTPS. This ensures that all connections to your website are encrypted and secure, providing an extra layer of protection for your users' data. Regularly monitor your web server logs and periodically test the redirection to ensure its continued functionality.

Did this answer your question?