我有一个.htaccess
文件,这些规则的工作:的.htaccess不与CSS文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
我也有一个Router.php
文件:
<?php
class Router
{
function __construct()
{
print_r($_GET);
$this->request = $_GET['url'];
$this->request = rtrim($this->request, "/");
$this->params = explode("/", $this->request);
print_r($this->params);
$this->controller = $this->params[0];
if ($this->controller == "index.php")
$this->controller = "Index";
$this->controller = ucfirst($this->controller);
$file = 'controllers/' . $this->controller . '.php';
if (file_exists($file)) {
require_once $file;
$this->connection = new $this->controller($this->params);
} else {
$file = 'controllers/PageNotFound.php';
$this->controller = "PageNotFound";
require_once $file;
$this->connection = new $this->controller();
}
}
}
和header.php
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="utf-8">
<link href="resources/style.css" rel="stylesheet" type="text/css">
<title>System stypendialny</title>
</head>
<body>
我有一个.htaccess
文件的问题。当我使用这个版本的文件,我尝试在浏览器这个http://localhost/scholarship_system/ URL我看到这一点:
阵列() 公告:未定义指数:用C网址:\ XAMPP \ htdocs中\ scholarship_system \库\路由器在线路8 .PHP 阵列([0] =>)
但是,当我删除此行(RewriteCond %{REQUEST_FILENAME} !-f
),则CSS文件未加载。
'$ _GET ['url]'只存在于你试图访问的文件不存在的时候(这是你RewriteRule被触发的时候)。如果文件夹'/ scholarship_system /'存在,并且该文件夹中有一个'index.php',它将立即使用它而不用重写。 –
这是正确的,但如果我删除行RewriteCond%{REQUEST_FILENAME}!-f 我得到这$ _GET阵列([url] => index.php) –
这会给你更多的问题与您的CSS,图像和其他资产。我已经添加了一个可以解决您的问题的答案。 –