L
L
LIUDMYLA DUVIVIER2020-04-18 19:31:17
PHP
LIUDMYLA DUVIVIER, 2020-04-18 19:31:17

The site is running on a test server localhost:8000. What is the correct way to create .htaccess to run on a remote server?

When starting the site, the run() function is used
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';
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;

}
On the local server localhost:8000 $view returns the expected post/index value and everything works

On merlu.akoatic.ovh/~myla/public error App\Router::run(): Failed opening required '/home/myla/www/views/.php' (include_path='.:/usr/share/php') $view returns false and site doesn't start

On XAMPP localhost/php/public/public the error is essentially the same Trying to access array offset on value of type bool $view returns false and the site does not start

In the index.php file,
$router = new App\Router(dirname(__DIR__) is used to start .'/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','
->post('/logout','auth/logout','logout')
->run();

The index.php file is located in the public folder, there are src , views and vendor folders, and all this is located in the root folder of the project, also called public.
Do I understand correctly that .htaccess is needed to run a project on a remote server? I tried to create it in the following configuration, but nothing works so far.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule / index.php [L]

This is my first time building a website, so don't judge too harshly. Thanks in advance for your help.
Here is the full version of the code https://gitlab.com/Liudmilla/annonces_russes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LIUDMYLA DUVIVIER, 2020-04-20
@Ludafr

I answer myself, this configuration works, put .htaccess in the root folder
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R= 302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question