Method 1
- Create .htaccess file under the root of the web folder
where www.coolexample.com should change to the url of the website
- Check the line LoadModule rewrite_module modules/mod_rewrite.so in /etc/httpd/conf.modules.d/00-base.conf is not comment or missing. If it is commented or missed, the mod_rewrite of Apache is not enabled.
- Edit the /etc/httpd/conf/httpd.conf to allow override
AllowOverride All
</Directory>
</Directory>
- Restart the Apache to put the change into effect
Method 2
- vi /etc/httpd/conf.d/ssl.conf
- Add following
ServerAdmin webmaster@your domain name
DocumentRoot /var/www/html/your folder root
ServerName your server name
RewriteEngine on
RewriteRule ^(.*) https://your domain name$1 [R=301,L]
</VirtualHost>