Hi, I'm using XAMPP on Windows and ONLY have a .htaccess and an index.php file in the htdocs folder.
ALL OTHER php files including routes.php and router.php are in a folder outside htdocs named src.
The website works just fine when on XAMPP BUT NOT IN LAMP. Here is the content of the files:
<?php
require_once("../src/routes.php");
?>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.css|\.svg|\.js)$
RewriteRule (.*) index.php [QSA,L]
<?php
require_once("../src/router.php");
get('/', '../src/home.php');
get('/register', '../src/register.php');
get('/signup', '../src/register.php');
get('/login', '../src/login.php');
any('/any','../src/any.php');
<?php
session_name('session');
session_start();
function get($route, $path_to_include){
if( $_SERVER['REQUEST_METHOD'] == 'GET' ){ route($route, $path_to_include); }
}
function post($route, $path_to_include){
if( $_SERVER['REQUEST_METHOD'] == 'POST' ){ route($route, $path_to_include); }
}
function put($route, $path_to_include){
if( $_SERVER['REQUEST_METHOD'] == 'PUT' ){ route($route, $path_to_include); }
}
function patch($route, $path_to_include){
if( $_SERVER['REQUEST_METHOD'] == 'PATCH' ){ route($route, $path_to_include); }
}
function delete($route, $path_to_include){
if( $_SERVER['REQUEST_METHOD'] == 'DELETE' ){ route($route, $path_to_include); }
}
function any($route, $path_to_include){ route($route, $path_to_include); }
function route($route, $path_to_include){
$ROOT = $_SERVER['DOCUMENT_ROOT'];
if($route == "/any"){
include_once("$ROOT/$path_to_include");
exit();
}
$request_url = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);
$request_url = rtrim($request_url, '/');
$request_url = strtok($request_url, '?');
$route_parts = explode('/', $route);
$request_url_parts = explode('/', $request_url);
array_shift($route_parts);
array_shift($request_url_parts);
if( $route_parts[0] == '' && count($request_url_parts) == 0 ){
include_once("$ROOT/$path_to_include");
exit();
}
if( count($route_parts) != count($request_url_parts) ){ return; }
$parameters = [];
for( $__i__ = 0; $__i__ < count($route_parts); $__i__++ ){
$route_part = $route_parts[$__i__];
if( preg_match("/^[$]/", $route_part) ){
$route_part = ltrim($route_part, '$');
array_push($parameters, $request_url_parts[$__i__]);
$$route_part=$request_url_parts[$__i__];
}
else if( $route_parts[$__i__] != $request_url_parts[$__i__] ){
return;
}
}
// Callback function
if( is_callable($path_to_include) ){
call_user_func($path_to_include);
exit();
}
include_once("$ROOT/$path_to_include");
exit();
}
function out($text){echo htmlspecialchars($text);}
function set_csrf(){
if( ! isset($_SESSION["csrf"]) ){ $_SESSION["csrf"] = bin2hex(random_bytes(50)); }
echo '<input type="hidden" name="csrf" value="'.$_SESSION["csrf"].'">';
}
function is_csrf_valid(){
if( ! isset($_SESSION['csrf']) || ! isset($_POST['csrf'])){ return false; }
if( $_SESSION['csrf'] != $_POST['csrf']){ return false; }
return true;
}
When I use the same code in LAMP on Ubuntu, only the localhost/ returns a 200 response (the homepage ../src/home.php is loaded corectly) and ALL OTHER PAGES return a 404 Not Found page. Any ideas how to make this work on LAMP?