using Mod_rewrite to redirect HTTP to HTTPS

前提是你 提交于 2020-01-15 07:57:24

问题


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]


来源:https://stackoverflow.com/questions/17521647/using-mod-rewrite-to-redirect-http-to-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!