虚拟化容器,大数据,DBA,中间件,监控。

Apache实现http跳转https

17 09月
作者:admin|分类:应用管理

利用Apache的    .htaccess 配置重定向http跳转到https


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

参考自:http 跳转到https的问题

也可以这样写:

   RewriteEngine On
   RewriteCond %{HTTPS} !on
   RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

附注:以上实现http跳转https方法测试成功。



如果需要整站跳转,则在网站的配置文件的<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://你的主机+网页


浏览1602 评论0
返回
目录
返回
首页
Linux查看端口被哪个进程占用 CentOS 7 APACHE2.4 +varnish+SSL自动跳转https