To redirect all HTTP requests to HTTPS, you can use the .htaccess file on an Apache server. Add the following code to the file:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This code checks if the connection is not secure (HTTP), then redirects it to the same URL with HTTPS. For Nginx, you can add the following to the server block:
server {
listen 80;
server_name yourdomain.com;
return 301 https://$host$request_uri;
}
This ensures all traffic is securely redirected.