I am experiencing some odd behavior with my URL routing system. I recently updated the PHP version of my server to PHP8 (from PHP 5.5), so I am not sure if it started then, or if was something that I just had never noticed prior.
Here is a rundown of the issue:
I get the expected result when I visit /login/ to my application, however, if I visit /user/login/ then it still displays my login page, versus a page for the user login.
Here is my .htaccess:
# ----------------------------------------------------------------------
# | Rewrite engine |
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
Here is my simple routing:
<?php
@list($page_url,$url_vars) = explode('?',$page_url);
$rules = array(
'{login/$}' => 'login.php',
'{logout/$}' => 'login.php?action=logout',
'{dashboard/$}' => 'dashboard.php',
'{feed/$}' => 'feed.php',
'{ajax/([^/]+)$}' => 'ajax.php?action=$params[1]',
'{user/([^/]+)/$}' => 'user.php?username=$params[1]&albums=false',
);
$found = false;
foreach ($rules as $pattern => $target) {
if (preg_match($pattern, $page_url, $params)) {
@list($page,$query) = explode('?',$target);
$query = preg_replace_callback('/$params[(d+)]/',function($m) use ($params) {
return $params[$m[1]];
}, $query);
parse_str($query, $url_query_vars);
/*
foreach ($url_query_vars as $var => $value) {
$query_vars[$var] = $value;
}
*/
extract($url_query_vars);
//print_r($url_query_vars);
require $page;
$found = true;
break;
}
}
?>
Basically, /ajax/feed/
is getting routed feed.php
or /user/login/
is getting routed to login.php
and I can’t figure out what is causing the issue.
Anyone notice anything that may be the culprit?