Redirect protocol http to https on apache webserver


I have just installed a SSL certificate on my apache web server. What I need now is to redirect all existing traffic from port 80 HTTP to 443 HTTPS. What would be the best way to accomplish this task?

thank you

Dear atlas,

you need to add VirtualHost configuration in your apache configuration file. apache2.conf or httpd.conf

I put example of IP Address you can use FQDN like

<VirtualHost *:80>

    <IfModule mod_rewrite.c&gt;
        RewriteEngine On
        RewriteCond %{REQUEST_METHOD} ^TRACE
        RewriteRule .* - [F]
        RewriteCond %{REQUEST_METHOD} ^TRACK
        RewriteRule .* - [F]

        #redirect all port 80 traffic to 443
        RewriteCond %{SERVER_PORT} !^443$
        RewriteRule ^/?(.*)$1 [L,R]


but keep in mind you need to enable mod_rewrite for apache

Hope so it will help you out but in the case of having issues let me know about your linux distro, arch, kernel info.



alternatively, you can also try:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}