From b75ae2542af6eefbaaa7f93a77a72941f6f00eb9 Mon Sep 17 00:00:00 2001 From: Yasder5 <102179445+Yasder5@users.noreply.github.com> Date: Tue, 3 Mar 2026 22:23:25 +0100 Subject: [PATCH] htaccess fini --- .htaccess | 26 ++++++++++++-------------- controllers/AdminCtrl.php | 6 +++--- controllers/ProjectCtrl.php | 32 ++++++++++++++++---------------- controllers/UserCtrl.php | 12 ++++++------ entities/Project.php | 4 ++-- index.php | 8 ++++---- views/_partial/footer.tpl | 8 ++++---- views/_partial/header.tpl | 26 +++++++++++++------------- views/_partial/preview.tpl | 20 ++++++++++---------- views/addedit_project.tpl | 6 +++--- views/error_403.tpl | 2 +- views/error_404.tpl | 2 +- views/help.tpl | 4 ++-- views/home.tpl | 8 +++----- views/inscription.tpl | 2 +- views/login.tpl | 2 +- views/mail_message.tpl | 2 +- views/project_display.tpl | 22 +++++++++++----------- views/search.tpl | 6 +++--- views/signup.tpl | 2 +- views/user.tpl | 4 ++-- views/useredit.tpl | 2 +- 22 files changed, 101 insertions(+), 105 deletions(-) diff --git a/.htaccess b/.htaccess index 697ae9f..ac4b1ee 100644 --- a/.htaccess +++ b/.htaccess @@ -1,33 +1,31 @@ Options -Indexes -# --- Sécurité --- - - Require all denied - - Require all denied -RewriteEngine On +# Gestion des erreurs +ErrorDocument 404 /error/error_404 +ErrorDocument 403 /error/error_403 -# 2. Bloquer l'accès direct au dossier vendor +RewriteEngine On +RewriteBase / + +# Bloquer l'accès direct au dossier vendor RewriteRule ^vendor/ - [F,L] -# 3. Autoriser l'accès aux fichiers/dossiers physiques (images, css, js) +# Autoriser l'accès aux fichiers/dossiers physiques (images, css, js) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d -# 4. RACINE : accueil par défaut +# RACINE : accueil par défaut RewriteRule ^$ index.php?ctrl=project&action=home [QSA,L] -# 5. ID NUMÉRIQUE : /ctrl/action/42 +# ID NUMÉRIQUE : /ctrl/action/42 RewriteRule ^([a-zA-Z]+)/([a-zA-Z_]+)/([0-9]+)/?$ index.php?ctrl=$1&action=$2&id=$3 [QSA,L] -# 6. PSEUDO : /user/profile/johndoe +# PSEUDO : /user/profile/johndoe RewriteRule ^([a-zA-Z]+)/([a-zA-Z_]+)/([a-zA-Z0-9_-]+)/?$ index.php?ctrl=$1&action=$2&pseudo=$3 [QSA,L] -# 7. RÉÉCRITURE GÉNÉRALE (inclut tes erreurs) : /ctrl/action -# C'est cette règle qui va transformer "/error/error_404" -# en "index.php?ctrl=error&action=error_404" +# RÉÉCRITURE GÉNÉRALE : /ctrl/action RewriteRule ^([a-zA-Z]+)/([a-zA-Z_]+)/?$ index.php?ctrl=$1&action=$2 [QSA,L] \ No newline at end of file diff --git a/controllers/AdminCtrl.php b/controllers/AdminCtrl.php index d84cebe..670082b 100644 --- a/controllers/AdminCtrl.php +++ b/controllers/AdminCtrl.php @@ -32,7 +32,7 @@ $newCat->setName($_POST['new_category']); $objCategoryModel->insertCategory($newCat); $_SESSION['success'] = "La catégorie a bien été ajoutée"; - header('Location: index.php?ctrl=admin&action=admin'); + header('Location: '.$_ENV['BASE_URL'].'/admin/admin'); exit; } @@ -42,7 +42,7 @@ $editCat->setName($_POST['new_name']); $objCategoryModel->editCategory($editCat); $_SESSION['success'] = "La catégorie a bien été modifiée"; - header('Location: index.php?ctrl=admin&action=admin'); + header('Location: '.$_ENV['BASE_URL'].'/admin/admin'); exit; } @@ -73,7 +73,7 @@ $objUserModel->delete_soft($intUserId); $_SESSION['success'] = "L'utilisateur a été supprimé."; } - header("Location: index.php?ctrl=admin&action=admin"); + header('Location: '.$_ENV['BASE_URL'].'/admin/admin'); exit; } } diff --git a/controllers/ProjectCtrl.php b/controllers/ProjectCtrl.php index b92de5e..fc85dd1 100644 --- a/controllers/ProjectCtrl.php +++ b/controllers/ProjectCtrl.php @@ -79,7 +79,7 @@ */ public function search(){ - $strKeywords = $_POST['keywords']??''; + $strKeywords = $_POST['keywords']??""; $intAuthor = $_POST['author']??0; $intPeriod = $_POST['period']??0; $strDate = $_POST['date']??''; @@ -325,7 +325,7 @@ } $_SESSION['success'] = (!isset($_GET['id'])) ? "Le projet a bien été créé" : "Le projet a bien été modifié"; - header("Location:index.php"); + header('Location:'.$_ENV['BASE_URL']); exit; } else { $arrError[] = "Erreur lors de l'enregistrement en base de données"; @@ -373,11 +373,11 @@ $this->_display("project_display"); } else { - header("Location: index.php?ctrl=project&action=home"); + header('Location: '.$_ENV['BASE_URL'].'/project/home'); exit; } } else { - header("Location: index.php?ctrl=project&action=home"); + header('Location: '.$_ENV['BASE_URL'].'/project/home'); exit; } } @@ -395,7 +395,7 @@ $arrProject = $objProjectModel->findOne($projectId); if (!$arrProject) { - header("Location: index.php?ctrl=project&action=home"); + header('Location: '.$_ENV['BASE_URL'].'/project/home'); exit; } @@ -429,8 +429,8 @@ $objMail->Subject = "Projet : " . $objProject->getTitle(); - $url = "https://php.boulayoune.com/index.php?ctrl=project&action=display&id=" . $projectId; - + $url = $_ENV['BASE_URL'].'/project/display/'.$projectId; + $this->_arrData['projectTitle'] = $objProject->getTitle(); $this->_arrData['projectDescription'] = $objProject->getDescription(); $this->_arrData['projectUrl'] = $url; @@ -438,14 +438,14 @@ $objMail->Body = $this->_display("mail_message", false); if ($objMail->Send()) { - header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=ok"); + header('Location: '.$_ENV['BASE_URL'].'/project/display/'.$projectId.'?mail=ok'); } else { - header("Location: index.php?ctrl=project&action=display&id=".$projectId."&mail=fail"); + header('Location: '.$_ENV['BASE_URL'].'/project/display/'.$projectId.'?mail=fail'); } exit; } - header("Location: index.php?ctrl=project&action=home"); + header('Location: '.$_ENV['BASE_URL'].'/project/home'); exit; } @@ -459,7 +459,7 @@ $objProjectModel = new ProjectModel; $objProjectModel->accept($intId); - header("Location: index.php"); + header('Location: '.$_ENV['BASE_URL']); exit; } @@ -473,7 +473,7 @@ $objProjectModel = new ProjectModel; $objProjectModel->refuse($intId); - header("Location: index.php"); + header('Location: '.$_ENV['BASE_URL']); exit; } @@ -483,7 +483,7 @@ public function delete(){ if (!isset($_SESSION['user']) || $_SESSION['user']['user_status'] != 2) { - header("Location: index.php"); + header('Location: '.$_ENV['BASE_URL']); exit; } @@ -498,7 +498,7 @@ } } - header("Location: index.php"); + header('Location: '.$_ENV['BASE_URL']); exit; } @@ -518,7 +518,7 @@ } $urlRedirect = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "index.php"; - header("Location: " . $urlRedirect); + header('Location: ' . $urlRedirect); exit; } @@ -541,7 +541,7 @@ } $url = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : "index.php"; - header("Location: " . $url); + header('Location: ' . $url); exit; } diff --git a/controllers/UserCtrl.php b/controllers/UserCtrl.php index cd0b3e2..7ecb8a9 100644 --- a/controllers/UserCtrl.php +++ b/controllers/UserCtrl.php @@ -48,7 +48,7 @@ class UserCtrl extends MotherCtrl { setcookie('remember_me', $token, time() + (15*24*60*60), "/", "", true, true); } - header("Location:index.php"); + header("Location:".$_ENV['BASE_URL']); exit; } } @@ -75,7 +75,7 @@ class UserCtrl extends MotherCtrl { $_SESSION['success'] = "Vous êtes bien déconnecté"; - header("Location:index.php"); + header("Location:".$_ENV['BASE_URL']); exit; } @@ -143,7 +143,7 @@ class UserCtrl extends MotherCtrl { if ($boolInsert === true) { $_SESSION['success'] = "Compte créé avec succès"; - header("Location:index.php?ctrl=user&action=login"); + header("Location:".$_ENV['BASE_URL']."/user/login"); exit; } else { $arrError['global'] = "Erreur lors de l'ajout"; @@ -169,7 +169,7 @@ class UserCtrl extends MotherCtrl { $arrUserData = $objUserModel->findUserByPseudo($strPseudo); if ($arrUserData === false) { - header("Location: index.php"); + header("Location: ".$_ENV['BASE_URL']); exit; } @@ -195,7 +195,7 @@ class UserCtrl extends MotherCtrl { */ public function edit(){ if(!isset($_SESSION['user'])){ - header("Location: index.php"); + header("Location: ".$_ENV['BASE_URL']); exit; } $objUserModel = new UserModel; @@ -298,7 +298,7 @@ class UserCtrl extends MotherCtrl { $arrNewInfo = $objUserModel->findUserByPseudo($objUser->getPseudo()); $_SESSION['user'] = $arrNewInfo; $_SESSION['success'] = "Compte modifier avec succès"; - header("Location:?ctrl=user&action=user&pseudo=".$objUser->getPseudo()); + header('Location:'.$_ENV['BASE_URL'].'/user/user/'.$objUser->getPseudo()); exit; } else { $arrError['global'] = "Erreur lors de l'update"; diff --git a/entities/Project.php b/entities/Project.php index 5071b57..ca5c941 100644 --- a/entities/Project.php +++ b/entities/Project.php @@ -226,7 +226,7 @@ class Project extends Mother{ * Récupération de la date du projet supprimer * @return string date du projet */ - public function getProject_deleted_at(){ + public function getDeleted_at(){ return $this->_project_deleted_at; } @@ -234,7 +234,7 @@ class Project extends Mother{ * Mise à jour de la date de suppression de projet * @param string date du projet */ - public function setProject_deleted_at($project_deleted_at){ + public function setDeleted_at($project_deleted_at){ $this->_project_deleted_at = $project_deleted_at; } } \ No newline at end of file diff --git a/index.php b/index.php index 2c8dca6..950b04a 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,7 @@ safeLoad(); @@ -27,6 +25,8 @@ } if ($boolError) { - $error = new \Controllers\ErrorCtrl(); - return $error->error_404(); + http_response_code(404); // ← important pour le SEO et les navigateurs + $error = new \Controllers\ErrorCtrl(); + $error->error_404(); // ← pas de "return", juste l'appel + exit; // ← stoppe l'exécution après l'affichage } \ No newline at end of file diff --git a/views/_partial/footer.tpl b/views/_partial/footer.tpl index 199e6be..fd0d63c 100644 --- a/views/_partial/footer.tpl +++ b/views/_partial/footer.tpl @@ -4,15 +4,15 @@ - + \ No newline at end of file diff --git a/views/_partial/header.tpl b/views/_partial/header.tpl index e1bc5b5..326bcfb 100644 --- a/views/_partial/header.tpl +++ b/views/_partial/header.tpl @@ -3,8 +3,8 @@ - - + + Folliow{block name="title"}{/block} @@ -15,8 +15,8 @@
- - Logo + + Logo @@ -31,18 +31,18 @@