Remove public from url laravel

Rakesh Sharma      39 Comments  

Remove public from url laravel 5 and Lower versions:-

Default laravel access url will be so you need to remove “public” from url to get clean urls in laravel 5. let’s check how to remove public from url in laravel.

There is two solution to remove public from url laravel :-

1. Using .htaccess :-
Add following code in your .htaccess (if not exist create a .htaccess on laravel root directory)

    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]

2. using content moving :-

It’s a better and simple method to remove public from url laravel below are the steps to do this:-

1. Create a folder on root with named local(you can give any name).
2. Move all files except public folder in the local folder.
3. Move all the files of public to root directory and remove blank public folder.
so directory structure will be :-
a. local – which have all root files except public folder
b. all files of public folder.

  -- local
     -- app
     -- boostrap
     -- .gitattributes
     -- composer.json
     -- server.php
     -- and so on ----
  -- packages
  -- .htaccess
  -- favicon.ico
  -- index.php
  -- robots.txt

4. Now time to change some paths:-

Note:- Skip step (a) to remove public from url in laravel 5.

In laravel 5 directory structure has been changed also you will not found paths.php in bootstrap so this step need to be skip for laravel 5.
a. open local/bootstrap/paths.php and find below code

'public' => __DIR__.'/../public',

change with below code

'public' => __DIR__.'/../../',

b. open index.php (on root) and find below code

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

change with below code

require __DIR__.'/local/bootstrap/autoload.php';
$app = require_once __DIR__.'/local/bootstrap/app.php';

Now you have all set you can access url if still problem try with clear cache of browser.

Remove public from url laravel

  • Paresh

    I am successfully changed that but now i am trying to make some blade files in app folder but i cannot access it. I can access through typing manually url. My main url is localhost/laravel its run successfully but when i am click on project button or other button like contact button. i am redirect to localhost/project and i am trying to type manually in url like localhost/laravel/projects or localhost/laravel/about its working fine. can you help me for solving that.

    • you need to create a blade file in app/views/yourfilename.blade.php
      then controller and set up your get route for access this view file, hope this help

      • Paresh

        I am creating blade files inside view/pages/ folder.

        • Magori Kihore

          i think you need to start with and the url

          • Paresh

            Thanks. But i cannot understand, start from url means?

      • Paresh

        I am not create controller now. its required now if i am work for just templating

  • Drifter

    the solution 1 doesn’t work for me (1. Using .htaccess :-)
    after that when I go to http://localhost/laravel/ gives me a NotFoundHttpException.
    i have to go to http://localhost/laravel/index.php and it works…

    Mod_rewrite is enabled on apache because I can go to http://localhost/laravel/public/ and everything works.

    also, when i go to http://localhost/laravel/index.php and click a link (XPTO) it redirects to http://localhost/laravel/public/index.php/XPTO

  • Nageswara Rao

    Thanks. Its working fine for me


    Aside from my homepage all I get is 404s now

    • i think you doesn’t follow steps correctly or have miss configured laravel

    • Katie Rose

      I had the same problem: After moving the contents of /laravel/public into my /public_html folder and updating index.php and .htaccess I was able to access my Laravel site directly from the www domain root, but all other subdomains were routing to their respective subfolders (e.g., was rerouting to the and/or throwing a 404.

      I modified my .htaccess to the alternate code listed in the Laravel setup/config docs for Apache and this seems to have resolved the issue, although I think I still have some caching issues with the pages I have already visited.

      Anyway, I used the following .htaccess (completely overwriting the original .htacess supplied by Laravel) and it resolved it for me:

      Options +FollowSymLinks
      RewriteEngine On

      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [L]

  • OzanKurt96

    My .htaccess file doesn’t work? What can be the problem?

    • check you mod_rewrite enabled on your server

      • OzanKurt96

        Last night it worked somehow :) Thanks you alot you have saved the day!

  • Deni Firdaus Waruwu

    Hai,, it doesn’t work on my app, i still need to add index.php to access my app. how can i solve that?


    • rakesh sharma

      just move your htaccess also on root and add code to remove index.php (default file already have code to remove if not then add)

  • Madula Shokeng Selowa

    i get this message Whoops, looks like something went wrong.

    • rakesh sharma

      On removing public? may be you missing .htaccess to move?

  • Madula Shokeng Selowa

    Running the laravel 5.1.3 on LAMP shows this error, tried all websites to fix this with no luck. Thanks for you help in advance.

    • rakesh sharma

      I think you need to first follow installation steps correctly read this : then try to remove public.

    • bijaya

      normally using php artisan serve and then localhost:8080 i didnt get any problem but i want to use it using localhost/laravel also

  • Bayu Lingga

    Great Its Works Thanks

  • Pawan Joshi

    Great tutorials.. :)

  • Niladri Banerjee

    Thanks for the nice tutorial. The core laravel application working fine without typing the public keyword. However, I see the alias stops working. When typing http://localhost/laraveldemo, it redirect me to http://localhost/public which is 404. Please advise.

    • rakesh sharma

      I think you missed some config. like move htaccess to root or may be replace dir in index.php

      • Niladri Banerjee

        Yes, I see that htaccess file in the root. This is because I have copied the public folder to root as specified in your tutorial. However, I can’t get your point – “may be replace dir in index.php”. Please suggest.

  • rainbow_hce

    The solution second that change folder structure is great

  • Tom

    Please be careful when using method 2, because you also need to re-declare public_path() function to use correct path:

  • FreeSpeech101

    Second solution is best


    The solution Second is running in my app but when am trying to migrate they will shows an error like
    Could not open input file: artisan

  • Samyak Upadhyay

    This worked!!! Thanks

  • 이한준

    Second way works well in my LAMP! Thanks.

  • Yousef Altaf

    everything is working fine ,but when try to run ‘composer update’, ‘composer dump-autoload’ gives an error : Composer could not find a composer.json file in C:wampwwwproject
    To initialize a project, please create a composer.json file as described in the “Getting Started” section

    how can I solve this??

  • Dev Geek

    Wrong htaccess solutions, doesn’t work with laravel 5.3

  • excellent help for laravel, thanks man

  • SeifEddine BelHadjAli

    Thanks Man !!

  • Naren Srem

    For solution 2, where should I store upload files/images? Is it in root/uploads/…..jpg/.doc/.docx/.pdf ?

  • murilo

    hello my friend , very good tutorial .I had done like this example .
    It worked ok , the laravel folder I created at one place and the public folder , I created in the public folder . It worked ok .

    But the probleme is when I gonna make a upload of a image , in my admin area . The image was suppose to go to my public folder/assets/images/myimage.jpg
    but is goint to my laravel application ->
    laravel/public/assets/images/myimage.jpg .

    It seams that I need to change as well the public path directory to laravel make the upload outside the laravel structure folder ,and make the upload inside the root folder that I created ( the public ) do you know how I can do it ?

    I make upload like this –
    $file->move(public_path(‘/assets/temp’), $main_image_filename);
    (It was supose to go to assets , but is going to local/laravel/public/assets…. )

    Thanks my friend

  • lina munawwar

    i’m using laravel 5.1, i couldn’t find paths.php in my bootstrap folder, can you help me?