簡體   English   中英

PHP 站點在 localhost:8000 上運行正確,但在 XAMPP 或其他服務器上出現錯誤。 如何創建 .htaccess?

[英]PHP site run correct on the localhost:8000 but gives erreurs on XAMPP or other server. How to create .htaccess?

這是我在 PHP 中創建站點的第一次體驗。 我的項目在 php 互聯網服務器上運行正確,但在服務器 ovh 上的 Xampp ni 上運行不正確

ovh serverur erreur: App\Router::run(): 未能打開所需的 '/home/myla/www/views/.php' (include_path='.:/usr/share/php': var $view false

localhost:8000 工作正確:var $view post/index

XAMPP 錯誤:嘗試訪問 bool 類型值的數組偏移量:var $view false

問題出在 function run() 的 var $view 中。

public function run ():self
{
$match = $this->router->match();
$view= $match['target'] ;
$params= $match['params'];
$router= $this;
$isAdmin= strpos($view, 'admin/') !== false;
$isUser =strpos($view, 'user/') !== false;
if(!$isAdmin && !$isUser){
$layout = 'layouts/default';
}
if($isUser){
$layout = 'user/layouts/default';
}
if ($isAdmin) {
$layout = 'admin/layouts/default';
}
try{
ob_start();
require $this->viewPath . DIRECTORY_SEPARATOR . $view . '.php';
$content = ob_get_clean();
require $this->viewPath . DIRECTORY_SEPARATOR . $layout . '.php';
} catch (ForbiddenException $e) {
header('Location: ' . $this->url('login') . '?forbidden=1');
die();
}
return $this;

}

我在 index.php 中使用 run():

$router = new App\Router(dirname(__DIR__) . '/views');
$router
->get('/', 'post/index', 'home')
->get('/blog/category/[*:slug]-[i:id]', 'category/show', 'category')
->get('/blog/[*:slug]-[i:id]', 'post/show', 'post')
->match('/login','auth/login','login')
->match('/register','auth/register','register')
->post('/logout','auth/logout','logout')
->run();

我嘗試創建 .htaccess 來重寫規則,但我沒有找到好的配置。 文件索引.php 在文件夾 public 和文件夾 public,src,views 在項目的 racine 中。

RewriteEngine On

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

它不起作用。

你能幫我配置 .htaccess 提前謝謝。

這是一個很好的配置:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM