Apache uses. Htaccess to enforce HTTPS access

Time:2020-6-27

We can use Apache’s redirection rule of. Htaccess to implement HTTP forced jump to HTTPS to visit the website.Important: you must put the code in front of the contents of the. Htaccess file to ensure the redirection priority. )

The code is as follows:

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

perhaps

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

Or

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

Note: if it is in a subdirectory, you can use the

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

Copy the above code to. Htaccess.

In the above article, Apache uses. Htaccess to implement mandatory HTTPS access, which is the whole content shared by Xiaobian. I hope to give you a reference, and I hope you can support developepaer more.