Redirect protocol http to https on apache webserver

Hello,

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 yourdomain.com.

<VirtualHost *:80>
    ServerName 192.168.1.32

    <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 ^/?(.*) https://192.168.1.32/$1 [L,R]
   </IfModule>

</VirtualHost>

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.

Thanks

bnhashmi

alternatively, you can also try:

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

cheers…lubos