using Mod_rewrite to redirect HTTP to HTTPS

2019-07-10 01:46发布

问题:

I need to redirect from http://test-glad/redirect TO https://test-glad/start.do

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

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

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

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.

I am using Apache 2.2

Many Thanks

Tom

回答1:

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}

or

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]