apache http强制跳转到https

最近将在host1free上申请的免费vps改为了数据统计网站,做访客统计,为了数据安全,需要强制将http全部跳转到https安全链接!如果是对某个网页做跳转,我可以使用redirect 301 来做跳转,但是现在是需要整站跳转,只好使用apache mod_rewrite。

如果需要整站跳转,则在网站的配置文件的<Directory>标签内,键入以下内容:

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

如果对某个目录做https强制跳转,则复制以下代码:

RewriteEngine on
RewriteBase /yourfolder
RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [L,R]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

如果只需要对某个网页进行https跳转,可以使用redirect 301来做跳转!

redirect 301  /你的网页 https://你的主机+网页

此条目发表在技术, 网络分类目录,贴了, , , 标签。将固定链接加入收藏夹。