Redirect a website to https using .htacess file
Due to certain reason you minght need to run your website on SSL only. If you want to do this by making changes in your .htaccess file then below are the code snippen you need to add to your .htaccess file. Below code snippet redirects your website from non HTTP to HTTPS based on server port. Port 443 is being used for secure server.
RewriteEngine On RewriteCond %{SERVER_PORT} !=443 RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
If you are running your website under a particular folder and want to do the same under the particular folder only then. You need to write below code under your .htaccess file
RewriteEngine On RewriteCond %{SERVER_PORT} !=443 RewriteCond %{REQUEST_URI} yourfoldername RewriteRule ^(.*)$ https://www.yourrdomain.com/yourfoldername/$1 [R=301,L]
Now the .htaccess file with above code needs to be put under root directory and it will check if there is any request coming for particualar folder only it will automatically redirects it to https based url.
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments