Apache uses .htaccess to enforce https access

We can use Apache's .htaccess redirection rules to implement http to force a jump to https to access the website. Important: The code must be placed at the top of the .htaccess file content to ensure redirect priority.

 RewriteEngine On
 RewriteCond %{SERVER_PORT} 80
 RewriteRule ^(.*)$ https://www.arebz.com/$1 [R,L]

or

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.arebz.com/$1 [R=301,L]

or

RewriteEngine on
 RewriteBase /
 RewriteCond %{SERVER_PORT} !^443$
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

 

If it is in a subdirectory, you can use

 RewriteEngine On
 RewriteCond %{SERVER_PORT} 80
 RewriteCond %{REQUEST_URI} subfolder
 RewriteRule ^(.*)$ https://www.arebz.com/host [R,L]
 Copy the above code into .htaccess.
  • 366 Users Found This Useful
Was this answer helpful?

Related Articles

How to choose the cloud server?

★ Choose the right cloud server configuration based on your actual business needs: Understand...

How do I connect to my cloud server? (including linux and windows)

First of all to distinguish between linux and windows, including ubuntu, centos, debian are...

linux system data disk merged into the system disk

 Check it out, the current command: df -h [[email protected] ~]# df -h Filesystem...

Linux cloud server data disk expansion tutorial guide

This tutorial belongs to the data disk expansion [non-system disk] default directory /dev/sdb...

About the automatic synchronization of cloud server time, and the problem that time cannot be modified.

Recently, there have been user feedback, cloud server time cannot be modified. The solution is...