开启并强制全站 https 访问

主机供应商免费提供了 SSL 证书,于是也就给域名配置了。

开启 https 强制跳转

一般情况下用户访问网站时都不会专程加上  https://  来使用 HTTPS 协议连接,因而就需要在用户通过 HTTP 连接时强制跳转至 HTTPS 协议下。全站强制访问通过修改 .htaccess 文件实现。从服务器下载 .htaccess 文件,修改如下,注意编码格式为 ANSI 。

# BEGIN WordPress
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post/.php*
RewriteCond %{HTTP_REFERER} !.*adomikao.com.* [OR] RewriteCond %{HTTP_USER_AGENT} ^$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) ^http://adomikao.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]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) https://adomikao.com%{REQUEST_URI} [R=301,NC,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

 

编辑完成后上传服务器覆盖.htaccess 文件.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*