网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   闲话灌水 (https://www.0058.net/forumdisplay.php?f=13)
-   -   How do I Force my Website to use SSL? (https://www.0058.net/showthread.php?t=5937)

Umpire 2016-11-17 06:37 PM

How do I Force my Website to use SSL?
 
Forcing a specific domain to use HTTPS

To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website's root folder:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^abcd\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.xyz.com/$1 [R,L]

In the .htaccess code above, if abcd.com website is accessed, it will re-direct to https://xyz.com You will need to replace abcd\.com with the domain name you're forcing to https and also replace www.xyz.com with the domain name to where the website traffic will be re-directed. Here's an example:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test-site\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.some-website.com/$1 [R,L]

In the example above, any one typing in http://test-site.com will automatically be re-directed to https://some-website.com.
Forcing all website traffic to use HTTPS

In order to force all web traffic to use HTTPS, use the following code in your .htaccess file. If you are hosting multiple websites on your account, it is possible to have an .htaccess file for each website. Make sure that you are editing the .htaccess file that is in the root folder where you want the re-direct to occur.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]

Be sure to replace www.yourdomain.com with your actual domain name.
Forcing SSL on a specific folder

If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific folder:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]

Make sure you change the folder reference to the actual folder name. Then be sure to replace www.yourdomain.com/folder with your actual domain name and folder you want to force the SSL on.


All times are GMT +8. The time now is 08:54 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.