How to Setting https redirect using .htaccess?

HostSailor

Member
Registered
Joined
May 16, 2014
Messages
20
Points
1
If you are using an SSL certificate with your domain, you may need to set up a redirect when someone trying to access the domain with HTTP to load it with HTTPS automatically. We can use the following redirections as per your needs:
1. If you need to redirect all HTTP requests to HTTPS, paste the following in the .htaccess configuration:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https......................./$1 [R,L]
2. If you need to force SSL on a specific folder inside the home directory you can insert the following code into a .htaccess file placed in that specific folder:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https......................../folder/$1 [R,L]
*Please replace the domain 'example.com' with the actual domain name.
 

harry_v

Well-known member
Registered
Hosting Provider
Joined
Dec 20, 2017
Messages
110
Points
18
Hello,

If you have installed an SSL Certificate on your website and want to redirect your website traffic from http to https using the .htaccess file, you can follow the below steps,

You'll need to add the following code to your .htaccess file for the redirection.
  • Firstly, If you're looking to redirect a specific domain from HTTP to HTTPS, then add the following line to your .htaccess,
Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
  • Now, If you're looking to redirect a specific folder from HTTP to HTTPS, then add the following line to your .htaccess,
Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]
  • Lastly, If you're looking to redirect All Web Traffic from HTTP to HTTPS, then add the following line to your .htaccess,
Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
Note: You'll need to replace example.com with your domain name
wherever required in the code, and set the folder name wherever required.

Thus, I hope the ways mentioned above help you to redirect from HTTP to HTTPS using a .htaccess file without facing any issues.

-----------------------------
Regards,
harry_v
 

BlueLeaf

Well-known member
Registered
Joined
Apr 11, 2017
Messages
191
Points
18
How to Setting https redirect using .htaccess?

If you're looking to set up a website and want it to always use the HTTPS protocol, then you can do so by setting up an HTTPS redirect in the .htaccess file. This will ensure that all traffic coming through your domain is automatically redirected from HTTP to HTTPS, ensuring that all communication between server and browser is secure.

Creating an .htaccess file is quite simple; you just need to open a text editor, such as Notepad, and type in the code below:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The first line tells the server that the rewrite engine should be turned on. The second line states that if the connection is not secure (HTTPS), the third line defines how the rewrite rule should be applied. The “^” character indicates that this rule applies at the start of any URL path (i.e. before any directory or page names). The “(.*)” indicates that any characters after this point can be matched as part of this rule; in this case, it means that any page or directory name will also match. Finally, the URL provided in quotes is what will be used for any requests which match this rule; in this case, it takes whatever was originally requested (which matches “(.*)”), but switches it over to use HTTPS instead. Once you have saved this file with a “.htaccess” extension (make sure there are no spaces around the name), you then need to upload it into your website's root folder using FTP or SSH/SFTP protocols.

Once done, all requests which were previously accessing pages via HTTP will now be redirected over to HTTPS instead – keeping all communication between server and browser secure!
 
Newer Threads
Replies
0
Views
975
Replies
0
Views
1,613
Replies
6
Views
1,904
wcq
Replies
3
Views
1,407
Latest Threads
Replies
0
Views
115
Replies
0
Views
65
Replies
0
Views
57
Replies
1
Views
87
Recommended Threads
Replies
16
Views
5,504
Replies
2
Views
2,420
Replies
10
Views
4,551
Replies
2
Views
3,968

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top