Php 控制CSS和图像的路由器

Php 控制CSS和图像的路由器,php,css,Php,Css,我一直在关注PHP系列,当我尝试加载图像和样式表时遇到了一个障碍 所以看起来路由器正在寻找所有东西的路由 #0 /Users/Graham/Projects/OGPokedex/index.php(7): Router->direct('css/bootstrap.c...') #1 {main} thrown in /Users/Graham/Projects/OGPokedex/core/Router.php on line 21 [06-Apr-2017 09:08:28 Eur

我一直在关注PHP系列,当我尝试加载图像和样式表时遇到了一个障碍

所以看起来路由器正在寻找所有东西的路由

#0 /Users/Graham/Projects/OGPokedex/index.php(7): Router->direct('css/bootstrap.c...')
#1 {main}
  thrown in /Users/Graham/Projects/OGPokedex/core/Router.php on line 21
[06-Apr-2017 09:08:28 Europe/Berlin] PHP Fatal error:  Uncaught Exception: No route defined for this URI. in /Users/Graham/Projects/OGPokedex/core/Router.php:21
Stack trace:
#0 /Users/Graham/Projects/OGPokedex/index.php(7): Router->direct('css/bootstrap.c...')
#1 {main}
  thrown in /Users/Graham/Projects/OGPokedex/core/Router.php on line 21
[06-Apr-2017 09:08:28 Europe/Berlin] PHP Fatal error:  Uncaught Exception: No route defined for this URI. in /Users/Graham/Projects/OGPokedex/core/Router.php:21
Stack trace:
#0 /Users/Graham/Projects/OGPokedex/index.php(7): Router->direct('media/logo.png')
#1 {main}
  thrown in /Users/Graham/Projects/OGPokedex/core/Router.php on line 21
[06-Apr-2017 09:08:28 Europe/Berlin] PHP Fatal error:  Uncaught Exception: No route defined for this URI. in /Users/Graham/Projects/OGPokedex/core/Router.php:21
Stack trace:
#0 /Users/Graham/Projects/OGPokedex/index.php(7): Router->direct('js/bootstrap.mi...')
#1 {main}
  thrown in /Users/Graham/Projects/OGPokedex/core/Router.php on line 21
正如您所看到的,它无法加载任何此类的路由

这是路由器类

<?php

class Router {
    protected $routes = [];

    public static function load($file) {
        $router = new static;
        require $file;
        return $router;
    }

    public function define($routes){
        $this->routes = $routes;
    }

    public function direct($uri){
        if (array_key_exists($uri, $this->routes)){
            return $this->routes[$uri];
        }

        throw new Exception('No route defined for this URI.');
    }
}
这方面的任何帮助都会很好

编辑 我的htaccess文件 ```


```

在聊天室中快速讨论后,我们发现htaccess导致了问题。htaccess文件需要更改为

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}% !-d 
RewriteCond %{REQUEST_FILENAME}% !-f 
RewriteRule ^(.+)$ index.php [QSA,L]
如您所见,我们删除了
RewriteBase/

我猜想这一行导致资产URL(
/css
/js
等)在2
重写条件下无法识别为文件或目录。这意味着这些请求被重定向到
index.php

编辑

根据我上面的回答,找到了更稳定的
.htaccess
设置

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [L]

您是如何尝试包含CSS文件的?您在
.htaccess
文件中是否有规则将所有请求重定向到
index.php
文件?与图像相同--
我的htacces文件----RewriteEngine On RewriteBase/RewriteCond%{REQUEST\u FILENAME}%-已重写COND%{REQUEST_FILENAME}%-f重写规则^(+)$index.php[QSA,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}% !-d 
RewriteCond %{REQUEST_FILENAME}% !-f 
RewriteRule ^(.+)$ index.php [QSA,L]
Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^ index.php [L]