Skip to content

Redirect to a secure connection #175

Open
@wawanUnic

Description

@wawanUnic

Hello. Tell me how to redirect to a secure connection? I'm creating two servers, a secure one and a regular one. So, in the handler of a regular server, I would like to place a redirect to a secure server but preserving the link itself. So that any request to an unprotected server is immediately redirected while maintaining a link to a protected server. Here is an example of how this is done in Apache:

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

All redirects presented here take us to the root link of a secure server and the specific page is lost during the transition. This option doesn't suit me. I would be grateful for any help.

void handleRedirect(HTTPRequest* req, HTTPResponse* res) {
  req->discardRequestBody();
  res->setStatusText("Not Found");
  res->setHeader("Content-Type", "text/html");
  res->setHeader("Refresh", "5; URL=https://192.168.4.139");
  res->println("<!DOCTYPE html>");
  res->println("<html>");
  res->println("<head><title>Redirect</title></head>");
  res->println("<body><h1>Redirect on httpS...</h1><p>You will now be redirected to a secure page...</p></body>");
  res->println("</html>");
}

This will not work because the specific request will be lost:
http://192.168.4.139/helloWord converts to https://192.168.4.139 but the Hello world request will be lost...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions