.htaccess 安全性
Updated 11/3/2015: Added R=301
to ensure redirects are 301 permanent.
2015年1月3日更新:添加了R=301
以确保重定向是301永久的。
A while back, I shared a method for forcing a secure page using PHP. What if you want to force SSL (https://) on an entire website though? You don't want to have to put force-SSL PHP code on every page, right? Well, the website's .htaccess file comes to the rescue.
不久前,我分享了一种使用PHP强制执行安全页面的方法 。 如果要在整个网站上强制使用SSL (https://) ,该怎么办? 您不想在每个页面上都放置强制SSL PHP代码,对吗? 嗯,该网站的.htaccess文件可助您一臂之力。
.htaccess代码 (The .htaccess Code)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
Obviously, you'll want to change "domain.com" to your domain. Another short snippet of code that has a big impact on your website!
显然,您需要将“ domain.com”更改为您的域。 另一个简短的代码段会对您的网站产生重大影响!
.htaccess 安全性