Wednesday, September 26, 2018

Enable and Configure http to https redirection for Apache on CentOS 7


Method 1
  • Create .htaccess file under the root of the web folder
         RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]

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
          <Directory /var/www/html>
     AllowOverride All
</Directory>
       



  • Restart the Apache to put the change into effect 
Method 2

  • vi /etc/httpd/conf.d/ssl.conf
  • Add following
      <VirtualHost *:80>
                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>

No comments:

Prevent or Prohibit Server Drives From Being Visible to Users

  To make changes to this policy for one of the seven default values: Start the Microsoft Management Console. On the Console menu, click  Ad...