An HTTP-to-HTTPS redirect sends visitors to the encrypted version of your website. Configure it only after the HTTPS site works with a valid certificate, so that visitors are not sent to an unavailable or untrusted address.

Why redirect HTTP to HTTPS?

HTTPS protects data in transit between the browser and the server. A redirect helps visitors using an old HTTP link reach the HTTPS address, but it does not fix vulnerabilities within the application.

Confirm that your certificate covers the hostnames visitors use and that the destination pages load correctly. Choose one of the following methods.

Method 1: Redirect using Apache Virtual Host

For a server you administer, add a redirect to the site’s existing HTTP virtual host. Replace the example hostnames with yours and preserve any other required configuration:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect 302 / https://example.com/
</VirtualHost>

This uses mod_alias; it does not require a rewrite rule. Keep the existing working HTTPS virtual host.

On Debian or Ubuntu, validate and then reload:

sudo apache2ctl configtest
sudo systemctl reload apache2

On a RHEL-based system using the httpd service:

sudo apachectl configtest
sudo systemctl reload httpd

Run the reload only if the configuration check succeeds. On a control-panel-managed server, use its supported configuration mechanism instead of editing generated virtual hosts directly.

Method 2: Redirect using .htaccess

Where Apache permits rewrite directives, back up and edit .htaccess in the website’s actual document root. Place the redirect before application rewrite rules:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://example.com%{REQUEST_URI} [R=302,L]

Replace example.com with the intended HTTPS hostname. The rule preserves the requested path and query string. It requires mod_rewrite and suitable override permissions; ask the provider if these are unavailable.

How to verify the HTTPS redirect

Open an HTTP page and confirm that it reaches the corresponding HTTPS page without certificate warnings. Test nested paths and links containing query parameters.

For a permanent change, replace 302 with 301 after testing. Browsers cache permanent redirects, so confirm the destination first.

Troubleshooting common issues

Check for competing redirects in the application, proxy and web server. If a proxy or load balancer terminates HTTPS, Apache’s local connection may be HTTP even for a secure visitor request. Use the platform’s trusted-proxy configuration rather than blindly trusting a client-supplied forwarding header.

Update any remaining HTTP resource links to avoid mixed-content errors. Do not disable certificate validation to hide a TLS problem.