The purpose of this tutorial is to assist in the creation of web page redirection with HTTP HyperText Transfer Protocol
to HTTPS Hyper Text Transfer Protocol Secure
. There are several ways to do this, however, we'll cover only one of them in this tutorial. The .htaccess
file will be used. = ]
This tutorial does not explain the installation and/or purchase of SSL security certificate. Another very important detail is that you need to get in touch with your hosting provider and identify if the procedure covered in this tutorial is allowed in your contracted plan.
Hosting with SSL
security certificate installed.
You can use the files available in this tutorial or create them on your own:
- The .htaccess file must be created in the root folder of the site, usually named
public
; - The folder test and the file test.html are optional and must also be created in the root folder of the site.
Assuming your hosting is already configured by enabling the HTTPS protocol, perform the following procedures:
Summary
- New file;
- Folder and test file;
- Send to the lodging.
Create a new file named .htaccess
and enter the following data:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^%{SERVER_NAME} [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
If your site already exists this file just add the above code. Do not forget to change
mydomain.com
to the correct one. \o/
To identify if the .htaccess
file is working, we will use a folder and a file as an example. ( This procedure is optional )
Create a folder named test and inside this folder create a file named test.html.
After performing the above procedures, send the folder and files to your hosting. Use your favorite FTP program to do this.
The structure of the folder and the files will look similar to the chart below:
├── test
│ └── test.html
├── .htaccess
Graphic example inspired by: https://github.com/willianjusten/braziljs-16
After performing all the previous procedures, access the links below:
www.yourdomain.com and also www.yourdomain.com/test/test.html
When loading the 2 pages, check if something similar appears with:
https://www.yourdomain.com and also https://www.yourdomain.com/test/test.html
If the address bar displays a lock
and the domain starts with https://
everything has occurred as expected. If this does not happen, I advise you to contact your hosting to see if this is allowed and if it was done correctly.
I am currently using this type of redirection in the hosting in which my site, and others managed by me, are stored. I do not want to promote or denigrate the image of any hosting provider. This tutorial has a single purpose that is to share something that helped a lot when I had to do this procedure.
It is always good to remember that this procedure should be performed with the guidance of your hosting!
Contribute to make this Redirecting HTTP pages to HTTPS model better. \o/
- Fork!
- Create your feature branch:
git checkout -b myNewFeature
- Confirm the changes:
git commit -am 'Add some comment'
- Send your branch:
git push origin myNewFeature
- Send a request for pull request.
= ]
This Redirecting HTTP pages to HTTPS is licensed under the MIT License - see the file LICENSE for details.