帮助中心 >  技术知识库 >  云服务器 >  服务器教程 >  centos apache 443,apache环境http跳转https

centos apache 443,apache环境http跳转https

2026-01-15 17:44:09 1120

linux 方法一RewriteEngine on


RewriteCond %{SERVER_PORT} !^443$


RewriteCond %{REQUEST_URI} !^/tz.php


RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]


解释:%{SERVER_PORT} —— 访问端口


%{REQUEST_URI} —— 比如如果url是 http://www.landui.com/tz.php,则是指 /tz.php


%{SERVER_NAME} —— 比如如果url是 http://www.landui.com/tz.php,则是指 localhost


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


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


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


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


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


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


方法二RewriteEngine On


RewriteBase /


RewriteCond %{SERVER_PORT} 80


RewriteRule ^(.*)$ /$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 ^(.*)?$ /$1 [R=301,L]


RewriteCond %{SERVER_PORT} !^443$


RewriteRule ^(.*)?$ /$1 [R=301,L]


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题:
XML 地图