diff --git a/src/URI.cpp b/src/URI.cpp index 0c6b465..efc3f02 100644 --- a/src/URI.cpp +++ b/src/URI.cpp @@ -59,9 +59,27 @@ URI::URI(string webroot, string reqpath) { } this->webroot = webroot; this->reqpath = reqpath; - this->info = ""; - string abs = reqpath; + info = ""; + relpath = reqpath; + + while (!fileExists(webroot + relpath) && !fileExists(webroot + relpath + ".php")) { + long slash = relpath.find_last_of('/'); + if (slash == string::npos) { + break; + } + info = relpath.substr(slash) + info; + relpath.erase(slash); + } + + cout << "info: " << info << endl; + cout << "rel: " << relpath << endl; + + if (!info.empty() && isDirectory(webroot + relpath)) { + relpath.append("/"); + } + + string abs = relpath; if (fileExists(webroot + abs)) { string ext = getExtension(abs); if (ext == "php" || ext == "html") { @@ -74,9 +92,10 @@ URI::URI(string webroot, string reqpath) { abs.erase(abs.length() - fname.length() - 1, abs.length()); } - this->filepath = webroot + reqpath; + this->filepath = webroot + relpath; if (isDirectory(webroot + abs)) { + cout << "DIR" << endl; if (abs[abs.length() - 1] != '/') { abs += "/"; } @@ -99,6 +118,29 @@ URI::URI(string webroot, string reqpath) { } } + cout << "Before rel: "<