繁体   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