我有一个.htaccess
文件,其中包含以下规则:
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我看到这个:
数组()注意:第8行C:''examplep''htdocs''scholarship_system''libs''Router.php中的未定义索引:url阵列([0]=>)
但是当我删除这一行(RewriteCond %{REQUEST_FILENAME} !-f
)时,CSS文件就不会被加载。
你可以保持.htaccess的原样。如果你删除-f条件,你的路由器将需要处理所有对css、图像和javascript文件的请求,这只是一种痛苦。
在路由器类中设置默认控制器:
$this->request = isset($_GET['url'])? $_GET['url] : 'default';
那么您只需要创建文件CCD_ 6,如果未设置CCD_。