If you have connected the domain to WordPress and completed HTTPS and SSL authentication, you may wonder if there is anything left to do. What’s left is HTTPS Redirection.
If you did not proceed with the domain connection and basic HTTPS authentication procedure, proceed from below.
Contents
- Experiments on HTTP
- HTTPS Redirection
- 1. bitnami.conf in /opt/bitnami/apache2/conf/bitnami
- 2. bitnami-ssl.conf in /opt/bitnami/apache2/conf/bitnami
- 3. 00_status-vhost.conf in /opt/bitnami/apache2/conf/vhosts
- 4. wordpress-https-vhost.conf in /opt/bitnami/apache2/conf/vhosts
- 5. wordpress-vhost.conf in /opt/bitnami/apache2/conf/vhosts
- *. Restart web server
Experiments on HTTP
Of course, there is no problem if you try to connect with HTTPS, and in general, browsers such as Chrome try to connect HTTPS first by entering only the domain address in the address bar.
However, what happens if you try to access the site via HTTP? There will be an unsafe site warning.
- https://www.molit.go.kr – OK
- http://www.molit.go.kr – NOK
Besides, what if the site registered in the search engine is an HTTP address?
The idea is simple, if someone tries to access via HTTP, it will automatically redirect to the HTTPS address.
HTTPS Redirection
According to Bitnami’s guide, the method is simple. You can open five files and add the same code. However, it is not simple to change my mind about uncertainty and annoyance. You can tie yourself up. Believe.
Bitnami’s code is as follows. Get ready to copy and paste.
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
If it is an AWS light sale-based wordpress, the following five commands open the file and restart web server.
sudo vim /opt/bitnami/apache2/conf/bitnami/bitnami.conf
sudo vim /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf
vim /opt/bitnami/apache2/conf/vhosts/00_status-vhost.conf
vim /opt/bitnami/apache2/conf/vhosts/wordpress-https-vhost.conf
vim /opt/bitnami/apache2/conf/vhosts/wordpress-vhost.conf
sudo /opt/bitnami/ctlscript.sh restart apache
1. bitnami.conf in /opt/bitnami/apache2/conf/bitnami
$ sudo vim /opt/bitnami/apache2/conf/bitnami/bitnami.conf
...
<VirtualHost _default_:80>
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
DocumentRoot "/opt/bitnami/apache/htdocs"
...
2. bitnami-ssl.conf in /opt/bitnami/apache2/conf/bitnami
$ sudo vim /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf
...
<VirtualHost _default_:443>
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
DocumentRoot "/opt/bitnami/apache/htdocs"
...
3. 00_status-vhost.conf in /opt/bitnami/apache2/conf/vhosts
$ vim /opt/bitnami/apache2/conf/vhosts/00_status-vhost.conf
<VirtualHost 127.0.0.1:80>
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
ServerName status.localhost
...
4. wordpress-https-vhost.conf in /opt/bitnami/apache2/conf/vhosts
$ vim /opt/bitnami/apache2/conf/vhosts/wordpress-https-vhost.conf
<VirtualHost 127.0.0.1:443 _default_:443>
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
ServerName www.example.com
...
5. wordpress-vhost.conf in /opt/bitnami/apache2/conf/vhosts
$ vim /opt/bitnami/apache2/conf/vhosts/wordpress-vhost.conf
<VirtualHost 127.0.0.1:80 _default_:80>
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
ServerName www.example.com
...
*. Restart web server
Restart the Apache.
$ sudo /opt/bitnami/ctlscript.sh restart apache
Restarted apache
If you see the error below, try again after 10 seconds. If it’s an error, let’s do it again for 10 seconds.
$ sudo /opt/bitnami/ctlscript.sh restart apache
Failed to restart apache: [apache] Other action already in progress -- please try again later
The last thing left is a test. Below are the test cases for HTTPS redirection.
- http://mydomain.com → https://mydomain.com
- http://www.mydomain.com → https://www.mydomain.com Or https://mydomain.com
- http://subdomain.mydomain.com → https://subdomain.mydomain.com
Sometimes Chrome does something stupid about recent changes. If you are a Chrome user, test with an edge browser, or, if not, with Chrome.
After testing, also you can check below.