I have a script to set up a VM server. The SSL certificate has to be completed by the user who sets up the VM. If they choose to ignore those steps, SSL will not be set up on the server. The html for the webpages however is given to the user along with the script and there are internal links. So I can't use https in the internal links. How do I selectively redirect http requests to https if SSL is set up on the server and otherwise deliver the content as http itself? If I write a .htaccess file with the rewrite conditions, it will continue to redirect http to https even if SSL is not set up right? In which case, my webpage won't load if SSL is not set up. I am using an Apache server and PHP (no frameworks) for server side processing.