简介
HTTP是超文本传输协议的缩写,而HTTPS是超文本传输安全协议的缩写,可见就是更加安全。为了得到浏览器前面的安全锁,相信有许多新手站长跟我一样,在没有好的工具辅助的前提下,想将http全站强制跳转到https会碰到很多困难。
问题
最让我头痛的就是,按照网上的教程,能够实现首页的强制跳转,但是其他的页面打开就变成了404,着实花了我很多时间。现将正确的跳转方式做个总结,分享给大家。
方法
全站强制跳转是通过修改网站根目录下的.htaccess
文件,如果没有该文件请创建。在该文件中的加入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
RewriteEngine On RewriteCond %{REQUEST_METHOD} POST RewriteCond %{REQUEST_URI} .wp-comments-post/.php* RewriteCond %{HTTP_REFERER} !.*finthon.com.* [OR] RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule (.*) ^http://finthon.com/$ [R=301,L] RewriteCond %{HTTPS} !on [NC] RewriteCond %{HTTP_USER_AGENT} !(baiduspider|soso|bing|sogou|yahoo|sohu-search|yodao|robozilla|msnbot|msie|feedburner) [NC] RewriteRule (.*) https://finthon.com%{REQUEST_URI} [R=301,NC,L] <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> |
将网站域名改成你自己的,然后保存,service httpd restart
重启apache服务。这样就实现了全站http强制跳转https了。