mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-20 01:09:35 +05:30
(feat): implemented basic url router and updated server .htaccess config
This commit is contained in:
4
htdocs/.htaccess
Normal file
4
htdocs/.htaccess
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
RewriteEngine On
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^(.+)$ index.php?url=$1[QSA,L]
|
||||||
43
htdocs/Router.php
Normal file
43
htdocs/Router.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
|
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];
|
||||||
|
|
||||||
|
$serverRoutes = [
|
||||||
|
'/' => 'home.php',
|
||||||
|
'/projects' => 'projects.php',
|
||||||
|
'/blog' => 'blog.php',
|
||||||
|
'/contact' => 'contact.php',
|
||||||
|
];
|
||||||
|
|
||||||
|
$devRoutes = [
|
||||||
|
'/neosubhamoy/htdocs/' => 'home.php',
|
||||||
|
'/neosubhamoy/htdocs/projects' => 'projects.php',
|
||||||
|
'/neosubhamoy/htdocs/blog' => 'blog.php',
|
||||||
|
'/neosubhamoy/htdocs/contact' => 'contact.php',
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($host == "localhost") {
|
||||||
|
$routes = $devRoutes;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$routes = $serverRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function routeTraffictToPages($uri, $routes) {
|
||||||
|
if(array_key_exists($uri, $routes)) {
|
||||||
|
require $routes[$uri];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
error_page(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function error_page($status_code) {
|
||||||
|
http_response_code($status_code);
|
||||||
|
require "error/{$status_code}.php";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
routeTraffictToPages($uri, $routes);
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -1042,10 +1042,6 @@ video {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.overflow-scroll {
|
|
||||||
overflow: scroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
.overflow-y-scroll {
|
.overflow-y-scroll {
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
}
|
}
|
||||||
|
|||||||
250
htdocs/home.php
Normal file
250
htdocs/home.php
Normal file
File diff suppressed because one or more lines are too long
251
htdocs/index.php
251
htdocs/index.php
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user