у меня есть .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 в браузере я вижу это:
Array() Примечание: Undefined индекс: URL в C: \ XAMPP \ HTDOCS \ scholarship_system \ ЛИЭС \ Router .php на линии 8 Array ([0] =>)
Но когда я удалить эту строку (RewriteCond %{REQUEST_FILENAME} !-f
), то файл CSS не загружен.
'$ _GET ['url]' существует только в том случае, если файл, к которому вы пытаетесь получить доступ, не работает (тогда вы запускаете RewriteRule). Если в папке существует '/ academics_system /' папка '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ', –
Правильно, но если я удалю строку RewriteCond% {REQUEST_FILENAME}! -f Я получаю это в $ _GET Array ([url] => index.php) –
Это даст вам больше проблем с вашими css, изображениями и другими активы. Я добавил ответ, который должен решить вашу проблему. –