Author Topic: Redirect from 80 (HTTP) to 443 (HTTPS)?  (Read 3469 times)

0 Members and 2 Guests are viewing this topic.

Offline eyespeak

  • Occasional poster
  • *
  • Posts: 4
    • View Profile
Redirect from 80 (HTTP) to 443 (HTTPS)?
« on: June 02, 2017, 01:52:55 PM »
Hi,

i have generated with Stunnel and Let´s Encrypt my own certificate without a SSL warning. Nice :-)

Now: how i can redirect alway all requests from port 80 to port 443?

Thanks a lot.

Offline bmartino1

  • Insane poster
  • *****
  • Posts: 750
  • I'm only trying to help i mean no offense.
    • View Profile
    • none - google translate
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #1 on: June 03, 2017, 08:24:56 AM »
iptables /nat traffice to via port forwarding starting port 80 to ending pot 443.

or

have a port 80 webpage that redirects you to the https site.

https://stackoverflow.com/questions/5411538/redirect-from-an-html-page

html code:

Code: [Select]
<meta http-equiv="refresh" content="0; url=http://example.com/" />
I'm only trying to help i mean no offense.
thank you for your time and patience,
Bmartino1

Follow members gave a thank to your post:


Offline LeoNeeson

  • Insane poster
  • *****
  • Posts: 433
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #2 on: June 03, 2017, 11:00:53 PM »
@eyespeak: I guess you own a domain, right?...
...or you are only using a DynDNS service (like No-IP)?

If you are using a domain, please say us what registrar are you using.
If you can give us more details, it would be more easy to help you. ;)
• HFS ahora también disponible en Español! (Clic aqui) :)
• HFS is now also available in Spanish! (Click here)

Offline eyespeak

  • Occasional poster
  • *
  • Posts: 4
    • View Profile
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #3 on: June 04, 2017, 02:42:04 AM »
Code: [Select]
<meta http-equiv="refresh" content="0; url=http://example.com/" />
Ok, it works but i have now a endless loop between http<>https. Not so good :)

Offline eyespeak

  • Occasional poster
  • *
  • Posts: 4
    • View Profile
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #4 on: June 04, 2017, 02:53:33 AM »
@eyespeak: I guess you own a domain, right?...
...or you are only using a DynDNS service (like No-IP)?
Yes, own domain with subdomain. I connect with sub.domain.de

Quote
If you are using a domain, please say us what registrar are you using.
My router has an account from selfhost.de, and my provider a CNAME entry on this subdomain. It works fine.

But how can I now only connect to https? The only way so far ... Only NAT 443 to internal:
NOT Working http://sub.mydomain.de
Working https://sub.mydomain.de

But I want to redirect from http to https directly:
http to https
https stay https
« Last Edit: June 04, 2017, 03:06:54 AM by eyespeak »

Offline LeoNeeson

  • Insane poster
  • *****
  • Posts: 433
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #5 on: June 04, 2017, 05:06:53 AM »
I'm not familiar with SelfHost.de but you can try this code:
Quote
<html>

<head>
   <script language="JavaScript">
      if (window.location.href.indexOf('http://')==0)
        window.location=window.location.href.replace('http://','https://');
   </script>

</head>

<body>



</body>

</html>
Insert the code marked in red in the <head> section (source).
• HFS ahora también disponible en Español! (Clic aqui) :)
• HFS is now also available in Spanish! (Click here)

Offline eyespeak

  • Occasional poster
  • *
  • Posts: 4
    • View Profile
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #6 on: June 04, 2017, 05:19:17 AM »
I'm not familiar with SelfHost.de but you can try this code:Insert the code marked in red in the <head> section (source).
Fine, the snippet works!
Is there any other option without JavaScript?

Offline LeoNeeson

  • Insane poster
  • *****
  • Posts: 433
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #7 on: June 05, 2017, 12:35:48 AM »
Is there any other option without JavaScript?
Probably using Macros, but I don't know if can be done. You can find another solution, here and also here.
• HFS ahora también disponible en Español! (Clic aqui) :)
• HFS is now also available in Spanish! (Click here)

Offline Mars

  • Operator
  • Insane poster
  • *****
  • Posts: 1818
    • View Profile
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #8 on: June 05, 2017, 08:33:20 AM »
Stunnel accepts only the ssl (HTTPS) request, if you want a http request to be redirected to https, a server listening on port 80 must redirect the url to the stunnel 443 port. You can run hfs listening only on address:port as 127.0.0.1:8443 with in stunnel a config like

[https]
accept = 0.0.0.0:443
connect = 127.0.0.1:8443
.....

you can use a second hfs stored in another folder ( not the same of the default server) to redirect request.
 this hfs must have his options saved to disk and hear port 80, no file in vfs and root template can be defined in diff template as
Quote
[=not found]
<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="5; url=https://sub.mydomain.de{.get|url.}">
        <title>Page Redirection</title>
    </head>
    <body>
        You will be redirected automatically to<p>
https://sub.mydomain.de{.get|url.} in 5 second
    </body>
</html>

all request http on port 80 are redirected to stunnel on port 443
« Last Edit: June 05, 2017, 08:35:35 AM by Mars »
FRENCH MEMBER : Si vous comprenez la langue française,  n'hésitez pas à l'utiliser pour une meilleure aide de ma part

Offline bmartino1

  • Insane poster
  • *****
  • Posts: 750
  • I'm only trying to help i mean no offense.
    • View Profile
    • none - google translate
Re: Redirect from 80 (HTTP) to 443 (HTTPS)?
« Reply #9 on: June 05, 2017, 04:12:38 PM »
The 0 should be a 1. In meta refresh rate the info loop is due to the page not fully loading.

As Mars has posted it's 5 seconds​ before refresh
I'm only trying to help i mean no offense.
thank you for your time and patience,
Bmartino1