Redirects

This commit is contained in:
2018-07-28 19:28:08 +02:00
parent 6c35622ef1
commit 811cd7be5a
2 changed files with 16 additions and 6 deletions

View File

@ -194,8 +194,21 @@ bool connection_handler(const char *preprefix, const char *col1, const char *col
pid_t childpid = 0; pid_t childpid = 0;
if ((host == "necronda.net" || socket->getSocketPort() != 443) && path.getRelativeFilePath().find("/.well-known/acme-challenge/") != 0) { bool redir = true;
req.redirect(303, "https://www.necronda.net/"); if (path.getRelativeFilePath().find("/.well-known/acme-challenge/") != 0) {
if (host == "necronda.net") {
req.redirect(303, "https://www.necronda.net/");
} else if (socket->getSocketPort() != 443) {
req.redirect(303, "https://" + host + req.getPath());
} else if (getWebRoot(host) == "") {
req.redirect(303, "https://www.necronda.net" + req.getPath());
} else {
redir = false;
}
}
if (redir) {
} else if (!path.getNewPath().empty() && req.getMethod() != "POST") { } else if (!path.getNewPath().empty() && req.getMethod() != "POST") {
req.redirect(303, path.getNewPath()); req.redirect(303, path.getNewPath());
} else { } else {

View File

@ -191,14 +191,11 @@ string read_line(FILE* file) {
#include "../CppNet/src/network/http/HttpConnection.cpp" #include "../CppNet/src/network/http/HttpConnection.cpp"
string getWebRoot(string host) { string getWebRoot(string host) {
if (host == "www.necronda.net") {
host = "www.necronda.net-new";
}
string root = webroot + host; string root = webroot + host;
if (fileExists(root)) { if (fileExists(root)) {
return root; return root;
} else { } else {
return (string) webroot + "www.necronda.net-new"; return "";
} }
} }