I'm trying to get apache to redirect from http to https, however I want them both on the same port (20100, but I doubt that will matter). Basically what's going on here except I'm not doing this for webmin. Currently I have it configured to serve HTTPS, and when I access with HTTP I get:

Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.

There seem to be a lot of somewhat similar questions, however I am unable to find one that actually answers my question.


This is not going to be possible with Apache. With Apache you cannot have HTTPS and HTTP running on the same port.

I am aware of a few port-multiplexers designed to make HTTPS/OpenVPN and SSH run on the same port, but these require additional software.

  • Damn. Oh well. Would it be possible to have apache simply redirect to the HTTPS version of the page from the HTTP version? – Finn Feb 13 '12 at 11:35
  • Sure. do a quick search here there are many questions that cover that. – Zoredache Feb 13 '12 at 15:37
  • Yeah so I've discovered, however they all assume that you're running http on port 80 and https on port 443. None (that i could find) work for to redirect http requests to https on the same port. – Finn Feb 13 '12 at 19:53
  • 2
    @thefinn93 The same port still won't work in Apache, regardless of what you're trying to answer with - a full page or a redirect. You need software in front of the listener that can make decisions on request routing based on the protocol the client sends - HAProxy may do the trick. But why go through all this effort - why not just use a different port? – Shane Madden Feb 13 '12 at 23:24
  • Alright. I assumed since apache was able to serve up something on that page it should be able to serve up redirect. Oh well, not really that important. Thanks! – Finn Feb 14 '12 at 3:12

This can be archived by redirecting to a custom "400 - Bad Request" page and modify the redirection with a rewrite rule. In the following example i request


and get redirected to


with one virtual host.


ErrorDocument 400 /

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

Or you simply redirect directly to the HTTPS version of the page.


 ErrorDocument 400 https://test.mydomain.com:27000

But you will loose the ability to redirect on a real "Bad Request" page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.