laravel remove public from url

2.86K views
3 Comments
6 Oct 2017 1:43 am

This is weird thing from #laravel on fresh installation, so everyone wants to remove public from url, there are two different methods.

1. Method is remove public from url in #.htaccess

Create .htaccess file on main directory of laravel and put the following code

<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

2. Method is remove public url moving files to parent path.

Go to installed laravel directory/public
move .htaccess, favicon.ico, index.php, robots.txt, web.config to laravel main directory.

move selected files from public to main installed laravel directory

open index.php which you moved from public folder to main directory.

change code from

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

to

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

NOTE:Your Email Address will be not shown and please do not add spamming comments because here is REL="NOFOLLOW" on your links and comments also moderated shown.
<code>Put html css or any language code under this tag</code>

3 Comments on laravel remove public from url
  • Saifullah Kaka

    Saifullah Kaka

    7 years ago

    very helpful, thank you

  • Saifullah Kaka

    Saifullah Kaka

    7 years ago

    In the first step, described that create a new file .htaccess and paste code that is given. Also in the second step, mentioned that move .htaccess and other 3 files from /public directory to root of project. There is a conflict create and move .htaccess (which file is mandatory the new created file or the moved) file.

    • These are two different methods.
      1. Method is remove public from url in #.htaccess
      2. Method is remove public url moving files to parent path.
      so you can follow one of them.