当网站开启HTTPS之后,肯定都希望将HTTP地址强制转换到HTTPS,所以,以树莓派Apache2为例,在"/etc/apache2/sites-enabled/000-default.conf"中
插入以下内容保存,再重新启动apache2即可实现。

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1  [L,R]

另外,以下内容保存为.htaccess放在外网主机根目录,即可实现:强制http转https,强制非www加www,

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^itvro.com [NC]
RewriteRule ^(.*)$ https://www.itvro.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.itvro.com/$1 [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

最后修改:2021 年 08 月 13 日
如果觉得我的文章对你有用,请随意赞赏