要强制所有网络流量使用HTTPS,在网站根目录下的.htaccess文件插入下面的代码
重要提示:如果你在.htacess已有代码,或者与之类似的前缀。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
请务必与实际域名替换www.yourdomain.com
要强制一个特定的域使用HTTPS,可在网站的根文件夹中的.htaccess文件中使用下面代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
请确保你正在试图更改https用域名来代替example\.com
此外,需要用实际域名替换来www.yourdomain.com
如果需要强制SSl在一个特定的文件夹,可以将下面的代码放置在特定的文件夹.htaccess文件中:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.yourdomain.com/folder/$1 [R,L]
请确保使用实际的文件夹名称。
当你想要强制执行SSL时,确保使用实际的域名和文件夹名来替换www.yourdomain.com/folder 。