I have a Laravel 5.0 project. When I enter wrong link on locahost, Laravel redirects me to custom error template, using this code on app\Exceptions\Handler.php.
public function render($request, Exception $e)
{
if($this->isHttpException($e)){
switch ($e->getStatusCode()) {
case '404':
\Log::error($e);
return \Response::view('error');
break;
case '500':
\Log::error($exception);
return \Response::view('error');
break;
default:
return $this->renderHttpException($e);
break;
}
}
else
{
return parent::render($request, $e);
}
}
After moving my laravel project to shared Hosting (not Linux) site does not redirect me to custom error template (views/error.blade.php)
, while entering wrong address which does not exist in app/http/routes.php
. I tried many solutions, configured .htaccess
file, but did not get a result. Error.log is empty. Here is my .htaccess
file:
AddHandler application/x-httpd-php54 .php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I also tried remove RewriteCond
and RewriteRule
lines. In this case I can get 404 error page, but it brings me problems:
1) Laravel will not recognize aliases, if exists. For example (www.site.com/news)
2) Laravel will not send post requests to another page, for example (www.site.com/post)
3) Laravel will not display custom error template (views/error.blade.php)
if I type wrong address, which not exists in app/http/routes.php,
For example (www.site.com/wrong)
For accessing site without public, I made some changes: 1) I moved all files from public_html
, except public folder
to applicaton
folder. Then, moved files from public
folder into public_html
.
2) Little changes in index.php
before:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
after:
require __DIR__.'/application/bootstrap/autoload.php';
$app = require_once __DIR__.'/application/bootstrap/app.php';
My files structure in public_html
:
application
app (inside application folder)
server.php (inside application folder)
.htaccess
index.php
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire