cPanelLauren

Product Owner
Staff member
Nov 14, 2017
13,297
1,251
313
Houston
This is fairly easily done by adding a rewrite rule for http (connections over port 80). You'd want to add this in WHM>>Server Configuration>>Apache Configuration -> Include Editor -> PreVirtualHost Include

I added the following to successfully redirect navigating to http://<MyIPAddress> to https://server.mydomain.tld:2087

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^12\.34\.56\.78$
RewriteRule ^(.*)$ https://server.mydomain.tld:2087$1 [L,R=301]
It's not as easily done for connections over https. The problem being that by default when you navigate to https://IPAddress on an Apache server it's behavior is to pull up the first SSL VirtualHost in the configuration with a valid SSL on that IP address.