Apache http自动跳转到https的几种方法

SSL admin 1161℃ 0评论

方法1

 RewriteEngine On
 RewriteBase /
 RewriteCond %{SERVER_PORT} 80
 RewriteRule ^(.*)$ https://yusky.me/$1 [R=301,L]

#这样跳转的好处是独立IP主机也支持,访问ip能自动跳转到https

方法二

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [R=301,L]
#整站跳转

方法三

RewriteEngine on
RewriteBase /yourfolder
RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)?$ https://%{SERVER_NAME}/$1 [R=301,L]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#以上至针对某个目录跳转,  yourfolder就是目录名

方法4

redirect 301  /你的网页 https://你的主机+网页
#至针对某个网页跳转

方法5

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

解释:

%{SERVER_PORT} —— 访问端口
%{REQUEST_URI} —— 比如如果url http://localhost/tz.php,则是指 /tz.php
%{SERVER_NAME} —— 比如如果url http://localhost/tz.php,则是指 localhost

转载请注明:主机优惠吧 » Apache http自动跳转到https的几种方法

喜欢 (0)

您必须 登录 才能发表评论!