xxxxxxxxxx
//Some exceptions describe HTTP error codes from the server. For example, this may be a "page not found" error (404),
//In order to generate such a response from anywhere in your application, you may use the abort helper:
return abort(404);
// OR
return abort(404, "page not found");
xxxxxxxxxx
// Create a file in resources/views/errors/404.blade.php and add this code.
@extends('errors::minimal')
@section('title', __('Not Found'))
@section('code', '404')
@if($exception)
@section('message', $exception->getMessage())
@else
@section('message', __('Not Found'))
@endif
abort(404, 'Whatever you were looking for, look somewhere else');
xxxxxxxxxx
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymlinks
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>
xxxxxxxxxx
// 1. Create a new view file for the custom 404 page.
// - In this example, let's assume the view file is named '404.blade.php'.
// - Create this file under the 'resources/views/errors' directory.
// 2. Configure the Laravel application to use the custom 404 page.
// - Open the 'app/Exceptions/Handler.php' file.
// - Find the 'render' method and update it as follows:
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
public function render($request, Throwable $exception)
{
if ($exception instanceof NotFoundHttpException && $request->wantsJson()) {
return response()->json(['error' => 'Resource not found'], 404);
}
return parent::render($request, $exception);
}
// 3. Configure Laravel to use the custom view for 404 errors.
// - Open the 'app/Exceptions/Handler.php' file again.
// - Add the following method to the 'Handler' class:
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Http\Response;
protected function renderHttpException(NotFoundHttpException $e)
{
if (view()->exists('errors.404')) {
return response()->view('errors.404', [], 404);
}
return (new SymfonyExceptionHandler(config('app.debug', false)))->render($e);
}
// That's it! Now when a 404 error occurs in your Laravel application,
// it will display the custom 404 page you created.
xxxxxxxxxx
# disable directory browsing, but specific file browsing is possible, e.g. /js/bootstrap.js
Options ExecCGI Includes IncludesNOEXEC SymLinksIfOwnerMatch
#To set which file will be acted as index file: DirectoryIndex index.php
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>
# deny from some DDoS attackers ip
# deny from 69.171.251.0/24
# php -- BEGIN cPanel-generated handler, do not edit
# This domain inherits the “PHP” package.
# php -- END cPanel-generated handler, do not edit