Question: How to automatically redirect HTTP request to HTTPS in Apache Web Server?
Answer: In this knowledge base article, we have explained manual mechanism to redirect websites from HTTP to HTTPS. Note that if you are using Hosting Controller control panel for managing your Linux websites then these steps are not required as we have explained in the end of this kb article.
Manual Steps: Using HC Panel interface when you enable SSL certificate on a website it will create only HTTPS (:443) entries in the apache web server. Those who do not want to map HTTP (:80) virtual host entry in apache then you can simply redirect the all non-secure web requests toward secure HTTPS by following below instructions:
- Access the Linux Server and go to path "/etc/httpd/conf.d"
- Create a file with name redirect.conf
- Open the file in editor vi redirect.conf and make an entry for a website that you want to redirect automatically from HTTP to HTTPS
Redirect permanent / https://linuxsite1.com/
Redirect permanent / https://mysite2.com/
Save the file and exit from editor
- Now open httpd.conf and include the redirect.conf file in it
save and exit
- Restart httpd service
Automated process via HC panel : As also explained above Http to Https redirection is already automated in HC panel and you don't have to do any manual tweaks for it.
Upon installing SSL certificate on a website via HC panel , HC panel automatically adds a file domain.com.conf under "/etc/httpd/hc" with the mechanism to redirect any http request to that website towards https URL.If this is not somehow working on your website then open ticket by sending an email to email@example.com