How to make my route accessible without using public in shared hosting using laravel, I tried to use this .htaccess but it is not working
RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]Im currently using hostinger and my folder structure is
->public_html ->laravel files
My index is inside public folder
I tried this .htaccess code but not working RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]
My index is inside public folder
CodePudding user response:
Move your index.php
and .htaccess
files under the public folder to parent folder.
Don't forget to fix the paths in your index.php
file. Like this:
// require __DIR__ . '/../vendor/autoload.php'; to...
require __DIR__ . '/vendor/autoload.php';
Your project will be triggered in public_html.
CodePudding user response:
The best practice for this case is by creating htaccess like this : How do you redirect all request to public/ folder in laravel 5
But we still have a "not too recommended" trick to handle limited functionality of hosting provider :
- Move all files in your project file (except "public" directory), and create new "private" folder. In this step, the "private" and "public" folder are in same level like this :
- private
- app
- bootstrap
- config
- database
- ...
- public
- index.php
- your_assets_or_anything
- ...
- Move all "public" directory content to root project. In this step, the directory structure will be like this :
- private
- app
- bootstrap
- config
- database
- ...
- index.php
- your_assets_or_anything
- ...
- Last open the "index.php" file that currently in root directory, replace all
/../
with/private/
. Example :
<?php
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// ...
if (file_exists($maintenance = __DIR__.'/private/storage/framework/maintenance.php')) {
require $maintenance;
}
// ...
require __DIR__.'/private/vendor/autoload.php';
// ...
$app = require_once __DIR__.'/private/bootstrap/app.php';
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
)->send();
$kernel->terminate($request, $response);
Keep in mind that this trick have a security issue. You need to protect all private files from public access.