Abhishek Saini
Abhishek Saini

Reputation: 5

How to remove public from laravel url

I want to remove public from my web URL simply step by step

I have done some steps already like copying the file from public the index and htaccess file but still I am getting not found page

Upvotes: 1

Views: 2959

Answers (3)

Karan Dhillon
Karan Dhillon

Reputation: 1234

I tried to solve this problem simply by making a .htaccess file. This file configures the apache server and solves the problem. Simply put this code in a file named '.htaccess' and save it in the root folder.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]

    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php
</IfModule>

Upvotes: 5

Mayur Panchal
Mayur Panchal

Reputation: 655

It's possible to remove public from url in laravel5. Follow these steps:

step 1 : copy all file from public and paste on root directory

step 2 : open index.php file replace with

require __DIR__.'/../bootstrap/autoload.php';

to

require __DIR__.'/bootstrap/autoload.php';

and

$app = require_once __DIR__.'/../bootstrap/app.php';

to

app = require_once __DIR__.'/bootstrap/app.php';

Then Remove all cache and cookies.

php artisan cache:clear

Upvotes: 0

Jagdish Sharma
Jagdish Sharma

Reputation: 309

If you have done 2 steps already have you change the index.php having vendor folder path inside remove the /../ and everything work fine

$app = require_once __DIR__/../'/bootstrap/app.php';

to

$app = require_once __DIR__.'/bootstrap/app.php'; 

Upvotes: 2

Related Questions