Can an HTTPS request be redirected to an HTTP request in Apache? If so, how?
2 Answers
Yes it can, and you'll want to use an Apache htaccess file to rewrite the request. It will need to be configured in your VHost config if you are using one so that you can match on the port, as Apache doesn't know what https is in htaccess.
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
This should redirect anything incoming on https to the matching page on http
Oh yes, I should mention that this will need to be in your .htaccess file in the root of your website, or in the folder you want to redirect. You'll also need to ensure that in your httpd.conf or vhost.conf (depending on config) that you have AllowOverride configured, otherwise your htaccess will not be read.
-
2It may be better to rely on
%{HTTPS}variable instead of specific port number .. as you can put HTTPS service on ANY port (depends on actual server condition/configuration/your requirements) -- 443 is just a default port, so you will have to edit this rule to make it work again if it is run on such non-standard port. Such alternate condition will beRewriteCond %{HTTPS} =on [NC]LazyOne– LazyOne2012-04-26 15:41:59 +00:00Commented Apr 26, 2012 at 15:41 -
Ah yes indeed. As with all things, there are many ways to reach the same goal :)David Yell– David Yell2012-04-26 16:24:24 +00:00Commented Apr 26, 2012 at 16:24
-
Just to clarify, to avoid browser errors, you'll still need to have a valid security certificate installed for this to work, since the HTTPS handshake occurs before .htaccess gets a chance to work on it.MrWhite– MrWhite2016-05-03 20:40:51 +00:00Commented May 3, 2016 at 20:40
To redirect HTTPS request to HTTP in Apache Server, I added code in .htaccess file. This code is working well. https://www.example.com/ is 301 Moved Permanently to http://www.example.com/ with a 200 OK response.
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
-
This code looks identical to the code already proposed in the other answer. Did you have anything new to add or are you just confirming that it worked for you?2018-04-27 10:21:21 +00:00Commented Apr 27, 2018 at 10:21
-
@StephenOstermiller - nice formatting, I couldn't work out what he was trying to post :PSteve– Steve2018-04-27 10:22:54 +00:00Commented Apr 27, 2018 at 10:22