Remove Public from Laravel URL

In this tutorial we will learn how to remove public from laravel url.You can use this method for laravel5 and lower versions.By default, the URL which comes with Laravel App will be this http://example.com/public/.So for getting clean URLs which are good for SEO purpose you will need to remove public from url in laravel application.There are two methods to remove public word in laravel url.

1.Using .htaccess

First check .htaccess in your laravel project if it is not there create a .htaccess in your root directory and add this code in your file.

2. Using Content Moving

Follow these steps to remove puclic from laravel url.

1.Make a new folder in your root directory with name project(you can give name according to your desire).

2.Now move all your files except the public folder into the project folder.

3.Now move all your public files into the root directory and then delete the blank folder from your laravel project.

4.Now your root directory will be look like this.

5.Now we will change some paths in the application.

You can skip step-1 if you are using Laravel5.

Step-1: Now open this local/bootstrap/paths.php in your application and find the below code.

Now change this code with the below code.

Step-2: Now open this index.php in your application find the below code

Now change this code with the below code.

Conclusion

In this tutorial, we’ve learned how to remove public word from the laravel app url.Now you can access your app like this http://example.com/.If still have problem then you have to clear your browser cache. If you have any questions about removing public in URL, let us know by commenting here.

  • Faisal Riaz

    Thank you for this tip. This is the most simple and good organize article for removing public word in laravel url. Thumbs up.

  • This problem occure only on shared hostings.

    The proper way to hide public folder is link domain into that folder not root of application.

  • Asif Iqbal

    You didn’t mentioned Laravel version here, I guess 2nd point is not for Laravel 5.x.

  • I’m using this solution from this link:

    http://stackoverflow.com/questions/28364496/laravel-5-remove-public-from-url

    Rename the server.php in the your Laravel root folder to index.php
    and copy the .htaccess file from /public directory to your Laravel root
    folder. — Thats it !! 🙂

    That’s working for me.
    But all resource files in /public directory couldn’t find and request urls didn’t work, because I used asset() helper.

    I changed /Illuminate/Foundation/helpers.php/asset() function as follows:

    function asset($path, $secure = null)
    {
    return app(‘url’)->asset(“public/”.$path, $secure);
    }

    Now everything works 🙂

    answered Sep 11 ’15 at 9:16
    Miron

    ….

  • Naren Srem

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