Home > Article > Operation and Maintenance > Apache redirect HTTP to HTTPS
Force HTTP redirection to HTTPS in Apache, many sites just need to always run with SSL. We need to ensure that every user must access the website via SSL. If any user tries to access the website using a non-ssl URL, he must be redirected to the SSL website.
This article will introduce about redirecting the website to ssl url every time using the apache mod_rewrite module.
Option 1:
Edit the virtualhost website in the apache configuration file and add the following options. Change www.example.com to your actual domain name.
Redirect permanent / https://www.example.com/
Option 2:
Edit the VirtualHost website in the Apache configuration file and add the following settings. You can also add the same settings in an .htaccess file in the document root of your website.
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
If you want to redirect a specific URL to https. Use the following settings. For example, if someone tries to access the always-secure.html file on the website. Users must use SSL to access the URL.
RewriteEngine On RewriteRule ^always-secure.html$ https://www.example.com/always-secure.html [R=301,L]
This article has ended here. For more exciting content, you can pay attention to the Linux Video Tutorial column on the PHP Chinese website! ! !
The above is the detailed content of Apache redirect HTTP to HTTPS. For more information, please follow other related articles on the PHP Chinese website!