diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000000000000000000000000000000000000..35063d8743786d749b419ea78c04fb6747cec5c1 --- /dev/null +++ b/.htaccess @@ -0,0 +1,6 @@ +Options -Multiviews + +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-d +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule ^(.*)$ index.php?url=$1 [L] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index eb4e8e5c36365752bfbebd8f9720a9a8e7249d21..287fc7a4c35d5c0d3a11e051d0de93a05f757478 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM php:8.0-apache COPY . /var/www/html +RUN a2enmod rewrite + RUN apt-get update \ && apt-get install -y libpq-dev \ && docker-php-ext-install pdo pdo_pgsql diff --git a/api/auth/login.php b/api/auth/login.php index 7695f9b0c4a3949fd6e515e7b8c1e4ba8863e96a..361f9daff17b13c2d61c9b10ca50e264777a91bd 100644 --- a/api/auth/login.php +++ b/api/auth/login.php @@ -17,15 +17,15 @@ if (isset($_POST['username'])) { if ($result == null) { $_SESSION['error'] = "Invalid username or password"; - header('location: ../../?login'); + header('location: ../../login'); } else { if (password_verify($password, $result['password'])) { $_SESSION['username'] = $username; $_SESSION['is_admin'] = $result['is_admin'] ? 1 : 0; - header('Location: ../../?learn'); + header('Location: ../../learn'); } else { $_SESSION['error'] = "Invalid username or password"; - header('location: ../../?login'); + header('location: ../../login'); } } } \ No newline at end of file diff --git a/api/auth/register.php b/api/auth/register.php index db1184a63008eb6705d163dd67be2f89da505bc2..7c3941a2297bf1aa743b755b115c5d777d573f14 100644 --- a/api/auth/register.php +++ b/api/auth/register.php @@ -40,10 +40,10 @@ if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['emai $rows = $user_model->register(array('username' => $username, 'password' => $password, 'email' => $email)); if ($rows) { - header('Location: ../../?login'); + header('Location: ../../login'); echo json_encode(array('status' => 'success', 'message' => 'User created')); } else { $_SESSION['error'] = "Something went wrong"; - header('Location: ../../?register'); + header('Location: ../../register'); } } diff --git a/app/controllers/Learn.php b/app/controllers/Learn.php index c4453b62bad8a313034e32a26d98491d4c6a2b24..968c0b96c54ec1bea14ab3bed18e78952cf456c0 100644 --- a/app/controllers/Learn.php +++ b/app/controllers/Learn.php @@ -3,7 +3,7 @@ class Learn extends Controller { public function index() { if (!$this->isLoggedIn()) { - header('Location: /?login'); + header('Location: /login'); exit(); } diff --git a/app/core/App.php b/app/core/App.php index dd7f5a336dad82d2f570694cffd91d40d343c1c5..73b24d872da8d858d101f8f7f9d2752a5513e7fa 100644 --- a/app/core/App.php +++ b/app/core/App.php @@ -39,15 +39,19 @@ class App { } public function parse_url() - { - if (isset($_SERVER['REQUEST_URI'])) { - $url = rtrim($_SERVER['REQUEST_URI'], '/'); - $url = ltrim($url, 'public/'); - $url = filter_var($url, FILTER_SANITIZE_URL); - $url = ltrim($url, '?'); - $url = explode('/', $url); - return $url; + { + if (isset($_SERVER['REQUEST_URI'])) { + if ($_SERVER['REQUEST_URI'] == '/') { + return ['']; } + $url = $_SERVER['REQUEST_URI']; + $url = preg_replace('#^/public/#', '/', $url); + $url = rtrim($url, '/'); + $url = explode('/', $url); + $url = array_values(array_filter($url)); + + return $url; } } + } \ No newline at end of file diff --git a/app/views/home/index.php b/app/views/home/index.php index 2135f392ec96b5613f801bb2f2f5de5839ff860f..cf71c6e3c5b31e7986f9bf04648ce8a32ceee996 100644 --- a/app/views/home/index.php +++ b/app/views/home/index.php @@ -15,7 +15,7 @@ $username = isset($_SESSION['username']) ? $_SESSION['username'] : null; <h1 class="text-xl font-bold text-blue-purple-gradient"> Your Path to <br> Multilingual Excellence </h1> - <a class="distinct-button get-started-btn font-reg text-sm" href="<?php echo $username ? '/?learn' : '/?login'; ?>"> + <a class="distinct-button get-started-btn font-reg text-sm" href="<?php echo $username ? '/learn' : '/login'; ?>"> Get Started </a> </div> diff --git a/app/views/learn/index.php b/app/views/learn/index.php index 382b2549bc19dbc6d0ab31d02fdbd994023e6d0d..56f6c8dc55f129fa26e24685886f576ea7671b78 100644 --- a/app/views/learn/index.php +++ b/app/views/learn/index.php @@ -17,7 +17,7 @@ </h1> <div class="learn-container"> <div class="learn-card"> - <a href="/?preview"> + <a href="/preview"> <div> <img class="learn-card-image" src="../../../public/icons/uk-flag.svg" alt="English" height="130px"> <h2 class="learn-card-header"> @@ -27,7 +27,7 @@ </a> </div> <div class="learn-card"> - <a href="/?preview"> + <a href="/preview"> <div> <img class="learn-card-image" src="../../../public/icons/id-flag.svg" alt="Indonesian" height="130px"> <h2 class="learn-card-header"> @@ -37,7 +37,7 @@ </a> </div> <div class="learn-card"> - <a href="/?preview"> + <a href="/preview"> <div> <img class="learn-card-image" src="../../../public/icons/fr-flag.svg" alt="French" height="130px"> <h2 class="learn-card-header"> @@ -47,7 +47,7 @@ </a> </div> <div class="learn-card"> - <a href="/?preview"> + <a href="?preview"> <div> <img class="learn-card-image" src="../../../public/icons/gr-flag.svg" alt="Germany" height="130px"> <h2 class="learn-card-header"> diff --git a/app/views/login/index.php b/app/views/login/index.php index 942b2cfaa95369f8fd2719a4d0257f5d72d1840a..4f471409a81c493bb730ba6a595c3461a707f022 100644 --- a/app/views/login/index.php +++ b/app/views/login/index.php @@ -36,7 +36,7 @@ </div> </form> <h3 class="login-desc1"> - <a class="login-desc1-click" href="/?register"> + <a class="login-desc1-click" href="/register"> Don't have an account yet? Register here </a> </h3> diff --git a/app/views/navbar/index.php b/app/views/navbar/index.php index b1995347dc4e1bdf34fcb87b228cb7150eecf494..ba3042339a8118ea1f80357055000dcaf58b3299 100644 --- a/app/views/navbar/index.php +++ b/app/views/navbar/index.php @@ -12,7 +12,7 @@ $is_admin = isset($_SESSION['is_admin']) ? $_SESSION['is_admin'] : null; </a> <ul class="nav-menu"> - <li><a href="<?php echo $username ? '/?learn' : '/?login'; ?>" class="text-sm text-black">Learn</a></li> + <li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li> <li><a href="/#" class="text-sm text-black">Articles</a></li> <li><a href="/#" class="text-sm text-black">Bootcamp</a></li> </ul> @@ -32,12 +32,12 @@ $is_admin = isset($_SESSION['is_admin']) ? $_SESSION['is_admin'] : null; <span class="text-sm"><?php echo $username; ?>'s learning</span> <?php endif; ?> <div> - <a href="/?profile"> + <a href="/profile"> <img id="profile-picture" src="/public/icons/profile.webp" alt="Profile picture" height="40px" draggable="false"> </a> </div> <?php else : ?> - <a href="/?login"> + <a href="/login"> <button class="login-btn text-sm primary-button font-reg"> Login </button> @@ -49,19 +49,19 @@ $is_admin = isset($_SESSION['is_admin']) ? $_SESSION['is_admin'] : null; </div> <div class="dropdown-menu"> <ul> - <li><a href="<?php echo $username ? '/?learn' : '/?login'; ?>" class="text-sm text-black">Learn</a></li> + <li><a href="<?php echo $username ? '/learn' : '/login'; ?>" class="text-sm text-black">Learn</a></li> <li><a href="/#" class="text-sm text-black">Articles</a></li> <li><a href="/#" class="text-sm text-black">Bootcamp</a></li> <?php if ($username) : ?> - <li><a href="/?logout" class="text-sm text-black"><?php echo $username; ?>'s learning</a></li> + <li><a href="/logout" class="text-sm text-black"><?php echo $username; ?>'s learning</a></li> <?php if ($is_admin) : ?> - <li><a href="/?cms" class="text-sm text-black">CMS</a></li> + <li><a href="/cms" class="text-sm text-black">CMS</a></li> <?php else : ?> - <li><a href="/?profile" class="text-sm text-black">Profile</a></li> + <li><a href="/profile" class="text-sm text-black">Profile</a></li> <?php endif; ?> <li><a href="../../../api/auth/logout.php" class="text-sm text-black">Logout</a></li> <?php else : ?> - <li><a href="/?login" class="login-btn text-sm primary-button font-reg">Login</a></li> + <li><a href="/login" class="login-btn text-sm primary-button font-reg">Login</a></li> <?php endif; ?> </ul> </div> diff --git a/app/views/register/index.php b/app/views/register/index.php index 488295937f86564ae827743b484f9cc32efe8902..5f5eb6c0d9c215abfc9eea755503b5aa8080a510 100644 --- a/app/views/register/index.php +++ b/app/views/register/index.php @@ -40,7 +40,7 @@ </div> </form> <h3 class="register-desc1"> - <a href="/?login" class="register-desc1-click"> + <a href="/login" class="register-desc1-click"> Already have an account? Login here </a> </h3>