phprouter / main

Secure router with XSS and CSRF
MIT License
511 stars 144 forks source link

Undefined URL with multiple subfolders 404 Problem #68

Open hkZeneus opened 4 months ago

hkZeneus commented 4 months ago

Good evening!

First of all i'm really greatful for this library, saves a lot of time and effort!

To recreate the problem I'm having, try accessing the URL: localhost/xxx/yyy/zzz I have not set a route for this, so it should redirect to 404. It does in fact redirect to 404, but the CSS/JS files I import into the project are always parsed as href="xxx/yyy/path/to/CSSorJS". is there a way to patch this other than adding a for loop to add "../" for every layer of the URL -1?

url error

Thanks in advance and kudos for the great work!

Shermalc commented 2 months ago

When routing files, you're always going to mess up the paths for dependencies, unless the router was designed to deal with this problem. I have overcome this with assigning a permanent path to the CSS or JS

<?php
$basedir = '/phprouter';
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="<?= $basedir.'/' ?>assets/style.css">
</head>

if your in public_html folder, then `$basedir='/';

Hope this helps :-)