使用Mod_rewrite将HTTP重定向到HTTPS [英] using Mod_rewrite to redirect HTTP to HTTPS

查看:82
本文介绍了使用Mod_rewrite将HTTP重定向到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从http://test-glad/redirect重定向到https://test-glad/start.do

主要问题是我需要在请求中维护POST参数.

The main problem being I need to maintain POST parameters in the request.

我无法使用标准的http重定向来执行此操作,因为POST参数没有按照RFC中的指定重新发送

I am unable to do this using standard http redirection as POST params aren't resent as specified in the RFC

我还尝试使用不起作用的Proxy Pass.

I have also tried using Proxy Pass which would not work.

我现在正在尝试使用Apache URL重写来实现此目的,但是很费劲.你知道这是否可能.如果是这样,将非常感谢您提供有关语法的帮助.

I am now trying to do this using Apache URL rewriting but struggling. Do you know if this is possible. If so some help with the syntax would be much appreciated.

我正在使用Apache 2.2

I am using Apache 2.2

非常感谢

汤姆

推荐答案

您要在localhost还是在线服务器上尝试? 将http重定向到https(整个网站使用SSL) 在.httaccess中尝试这个

are you trying it on localhost or on a live server? Redirect http to https (SSL for entire website) try this in .httaccess

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

RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ - [env=askapache:%2]

# redirect urls with index.html to folder
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index.html HTTP/
RewriteRule ^(([^/]+/)*)index.html$ http%{ENV:askapache}://%{HTTP_HOST}/$1 [R=301,L]

# change // to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)//(.*) HTTP/ [NC]
RewriteRule ^.*$ http%{ENV:askapache}://%{HTTP_HOST}/%1/%2 [R=301,L]

这篇关于使用Mod_rewrite将HTTP重定向到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆