URL Rewrites to Force Secure Connection #2183
-
Back in 2014 I used the following statement to force a secure connection. /* Redirect all traffic to ssl / If reviewing the current version of Mongoose, I do not see this function anymore. How would I implement this function in todays version of Mongoose? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Mongoose 3.6 is November 2015 |
Beta Was this translation helpful? Give feedback.
-
Something like this. (not tested) if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data;
mg_printf(c, "HTTP/1.1 301 Moved\r\nLocation: https://%M%.*s\r\n\r\n",
mg_print_ip, &c->loc, (int) hm->uri.len, hm->uri.ptr);
c->is_resp = 0;
} |
Beta Was this translation helpful? Give feedback.
If you need to send a 301, then send a 301: https://mongoose.ws/documentation/#mg_http_reply
AFAICS you don't have to force traffic, just tell the client to go to the secure URL and not serve pages at port 80. That means two listeners, one at port 80 returning 301 and the other at port 443 with TLS enabled
Something like: