linux apache 443,apache环境http跳转https (80跳转443)

直接在 .htaccess 文件中添加

方法一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

以上规则的意思是,如果访问的url的端口不是443,且访问页面不是tz.php,则应用RewriteRule这条规则。

这样便实现了:访问了 http://localhost/index.php 或者

http://localhost/admin/index.php 等页面的时候会自动跳转到

https://localhost/index.php 或者 https://localhost/admin/index.php,但是访问

http://localhost/tz.php 的时候就不会做任何跳转,也就是说 http://localhost/tz.php 和

https://localhost/tz.php 两个地址都可以访问。

方法二RewriteEngine On

RewriteBase /

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://www.firx.cn/$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就是目录名

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

#至针对某个网页跳转

方法六RewriteCond %{http_host} ^firx.cn [nc]

RewriteRule ^(.*)?$ https://www.firx.cn/$1 [R=301,L]

RewriteCond %{SERVER_PORT} !^443$

RewriteRule ^(.*)?$ https://www.firx.cn/$1 [R=301,L]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值