Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
BitsHost committed Nov 4, 2023
1 parent 7ca4079 commit 3df594e
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Options -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ - [R=404,L]
#RewriteRule ^ - [R=403,L]

#ErrorDocument 404
#ErrorDocument 403


#level One
RewriteRule ^test-([\w\d~%.:_\-]+)$ test?param=$1 [NC]
RewriteRule ^test-([\w\d~%.:_\-]+)/([\w\d~%.:_\-]+)$ test?param=$1&another=$2 [NC]

#level Two
RewriteRule ^moda-page-([\w\d~%.:_\-]+)$ moda-page?param=$1 [NC]
RewriteRule ^moda-page-([\w\d~%.:_\-]+)/([\w\d~%.:_\-]+)$ test?param=$1&another=$2 [NC]

RewriteRule (.+) index.php [QSA,L]
23 changes: 23 additions & 0 deletions Router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
class Router {
private $routes = [];

// Add a route and associate it with a page name and callback
public function addRoute($url, $pageName, $callback) {
$this->routes[$url] = ['page' => $pageName, 'callback' => $callback];
}

// Handle the current request and execute the associated code
public function handle($requestUri) {
foreach ($this->routes as $url => $route) {
if ($url === $requestUri) {
call_user_func($route['callback']);
return;
}
}

// Handle 404 - Page not found
include 'pages/404.php';
}
}
?>
25 changes: 25 additions & 0 deletions Routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
// Include the router file
require_once 'router.php';

// Initialize the router
$router = new Router();

// Define routes and associate them with page names
$router->addRoute('/', 'home', function () {
// Code for the Home page
include 'pages/home.php';
});

$router->addRoute('/about', 'about', function () {
// Code for the About page
include 'pages/about.php';
});

$router->addRoute('/contact', 'contact', function () {
// Code for the Contact page
include 'pages/contact.php';
});

// Handle the current request
$router->handle($_SERVER['REQUEST_URI']);
26 changes: 26 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
error_reporting(1);
// Include the router file
require_once 'router.php';

// Initialize the router
$router = new Router();

// Define routes and associate them with page names
$router->addRoute('/', 'home', function () {
// Code for the Home page
include 'pages/home.php';
});

$router->addRoute('/about', 'about', function () {
// Code for the About page
include 'pages/about.php';
});

$router->addRoute('/contact', 'contact', function () {
// Code for the Contact page
include 'pages/contact.php';
});

// Handle the current request
$router->handle($_SERVER['REQUEST_URI']);
10 changes: 10 additions & 0 deletions pages/404.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Not Found</title>
</head>
<body>
<h1>404 - Page Not Found</h1>
<p>The page you are looking for does not exist.</p>
</body>
</html>
10 changes: 10 additions & 0 deletions pages/about.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>About Page</title>
</head>
<body>
<h1>About Us</h1>
<p>Learn more about our company and our team.</p>
</body>
</html>
10 changes: 10 additions & 0 deletions pages/contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Contact Page</title>
</head>
<body>
<h1>Contact Us</h1>
<p>Feel free to get in touch with us using the contact information provided.</p>
</body>
</html>
10 changes: 10 additions & 0 deletions pages/home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Welcome to the Home Page</h1>
<p>This is the content for the home page.</p>
</body>
</html>

0 comments on commit 3df594e

Please sign in to comment.