简体   繁体   中英

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

This is my first experience to create a site in PHP. My project run correct on the php interne server, but not on the Xampp ni on the server ovh

ovh serveur erreur: App\Router::run(): Failed opening required '/home/myla/www/views/.php' (include_path='.:/usr/share/php': var $view false

localhost:8000 work correct: var $view post/index

XAMPP erreur: Trying to access array offset on value of type bool: var $view false

The probleme is in the var $view in the function run().

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;

}

I use run() in the index.php:

$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();

I try to create .htaccess to re-write the rule, but i didnt found the good configuration. File index.php is in the folder public and folders public,src,views are in the racine of the projet.

RewriteEngine On

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

Its not work.

Can you kindly help me to configurate .htaccess Thanks en advance.

Here is a good configuration:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM