Laravel 5 – Remove Public from URL












182















I know this is a very popular question but I haven't been able to find a working solution for Laravel 5. I've been trying to migrate from Codeigniter for a long time, but this convoluted installation process keeps putting me off.



I don't want to run a VM, this just seems awkward when switching between projects.



I don't want to set my document root to the public folder, this is also awkward when switching between projects.



I've tried the .htaccess mod_rewrite method



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


This just gives me a Laravel NotFoundHttpException in compiled.php line 7610.



When I tried L4 a while ago, I used the method of moving the contents of the public folder into the root. The structure of L5 is quite different and following the same steps completely broke Laravel (the server would only return a blank page).



Is there a decent method of removing 'public' in a development environment that:




  1. Works with L5

  2. Allows me to switch between projects with ease (I'm usually working on 2 or 3 at any one time).


Thanks



** I'm using MAMP and PHP 5.6.2










share|improve this question




















  • 1





    The folder structure in the guide is different to mine, I imagine he is not using L5? I omitted the changes he made to the Bootstrap/Paths file, because it doesn't exist. The project seems to be working though. Do you think this is ok?

    – user1537360
    Feb 6 '15 at 11:37











  • my mistake let me add answer for L5

    – kamlesh.bar
    Feb 6 '15 at 11:41











  • no success trying for same

    – kamlesh.bar
    Feb 6 '15 at 12:06








  • 1





    It seems to work by just modifying the paths in the index.php file, but I'm new to Laravel so obviously can't comment on whether this is stable / safe.

    – user1537360
    Feb 6 '15 at 13:06











  • The other folders/files are supposed to be underneath your document root.

    – Mike Rockétt
    Feb 7 '15 at 18:04
















182















I know this is a very popular question but I haven't been able to find a working solution for Laravel 5. I've been trying to migrate from Codeigniter for a long time, but this convoluted installation process keeps putting me off.



I don't want to run a VM, this just seems awkward when switching between projects.



I don't want to set my document root to the public folder, this is also awkward when switching between projects.



I've tried the .htaccess mod_rewrite method



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


This just gives me a Laravel NotFoundHttpException in compiled.php line 7610.



When I tried L4 a while ago, I used the method of moving the contents of the public folder into the root. The structure of L5 is quite different and following the same steps completely broke Laravel (the server would only return a blank page).



Is there a decent method of removing 'public' in a development environment that:




  1. Works with L5

  2. Allows me to switch between projects with ease (I'm usually working on 2 or 3 at any one time).


Thanks



** I'm using MAMP and PHP 5.6.2










share|improve this question




















  • 1





    The folder structure in the guide is different to mine, I imagine he is not using L5? I omitted the changes he made to the Bootstrap/Paths file, because it doesn't exist. The project seems to be working though. Do you think this is ok?

    – user1537360
    Feb 6 '15 at 11:37











  • my mistake let me add answer for L5

    – kamlesh.bar
    Feb 6 '15 at 11:41











  • no success trying for same

    – kamlesh.bar
    Feb 6 '15 at 12:06








  • 1





    It seems to work by just modifying the paths in the index.php file, but I'm new to Laravel so obviously can't comment on whether this is stable / safe.

    – user1537360
    Feb 6 '15 at 13:06











  • The other folders/files are supposed to be underneath your document root.

    – Mike Rockétt
    Feb 7 '15 at 18:04














182












182








182


101






I know this is a very popular question but I haven't been able to find a working solution for Laravel 5. I've been trying to migrate from Codeigniter for a long time, but this convoluted installation process keeps putting me off.



I don't want to run a VM, this just seems awkward when switching between projects.



I don't want to set my document root to the public folder, this is also awkward when switching between projects.



I've tried the .htaccess mod_rewrite method



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


This just gives me a Laravel NotFoundHttpException in compiled.php line 7610.



When I tried L4 a while ago, I used the method of moving the contents of the public folder into the root. The structure of L5 is quite different and following the same steps completely broke Laravel (the server would only return a blank page).



Is there a decent method of removing 'public' in a development environment that:




  1. Works with L5

  2. Allows me to switch between projects with ease (I'm usually working on 2 or 3 at any one time).


Thanks



** I'm using MAMP and PHP 5.6.2










share|improve this question
















I know this is a very popular question but I haven't been able to find a working solution for Laravel 5. I've been trying to migrate from Codeigniter for a long time, but this convoluted installation process keeps putting me off.



I don't want to run a VM, this just seems awkward when switching between projects.



I don't want to set my document root to the public folder, this is also awkward when switching between projects.



I've tried the .htaccess mod_rewrite method



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


This just gives me a Laravel NotFoundHttpException in compiled.php line 7610.



When I tried L4 a while ago, I used the method of moving the contents of the public folder into the root. The structure of L5 is quite different and following the same steps completely broke Laravel (the server would only return a blank page).



Is there a decent method of removing 'public' in a development environment that:




  1. Works with L5

  2. Allows me to switch between projects with ease (I'm usually working on 2 or 3 at any one time).


Thanks



** I'm using MAMP and PHP 5.6.2







php .htaccess laravel mamp laravel-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 29 at 0:32









Karl Hill

2,76612142




2,76612142










asked Feb 6 '15 at 11:13









user1537360user1537360

1,69051821




1,69051821








  • 1





    The folder structure in the guide is different to mine, I imagine he is not using L5? I omitted the changes he made to the Bootstrap/Paths file, because it doesn't exist. The project seems to be working though. Do you think this is ok?

    – user1537360
    Feb 6 '15 at 11:37











  • my mistake let me add answer for L5

    – kamlesh.bar
    Feb 6 '15 at 11:41











  • no success trying for same

    – kamlesh.bar
    Feb 6 '15 at 12:06








  • 1





    It seems to work by just modifying the paths in the index.php file, but I'm new to Laravel so obviously can't comment on whether this is stable / safe.

    – user1537360
    Feb 6 '15 at 13:06











  • The other folders/files are supposed to be underneath your document root.

    – Mike Rockétt
    Feb 7 '15 at 18:04














  • 1





    The folder structure in the guide is different to mine, I imagine he is not using L5? I omitted the changes he made to the Bootstrap/Paths file, because it doesn't exist. The project seems to be working though. Do you think this is ok?

    – user1537360
    Feb 6 '15 at 11:37











  • my mistake let me add answer for L5

    – kamlesh.bar
    Feb 6 '15 at 11:41











  • no success trying for same

    – kamlesh.bar
    Feb 6 '15 at 12:06








  • 1





    It seems to work by just modifying the paths in the index.php file, but I'm new to Laravel so obviously can't comment on whether this is stable / safe.

    – user1537360
    Feb 6 '15 at 13:06











  • The other folders/files are supposed to be underneath your document root.

    – Mike Rockétt
    Feb 7 '15 at 18:04








1




1





The folder structure in the guide is different to mine, I imagine he is not using L5? I omitted the changes he made to the Bootstrap/Paths file, because it doesn't exist. The project seems to be working though. Do you think this is ok?

– user1537360
Feb 6 '15 at 11:37





The folder structure in the guide is different to mine, I imagine he is not using L5? I omitted the changes he made to the Bootstrap/Paths file, because it doesn't exist. The project seems to be working though. Do you think this is ok?

– user1537360
Feb 6 '15 at 11:37













my mistake let me add answer for L5

– kamlesh.bar
Feb 6 '15 at 11:41





my mistake let me add answer for L5

– kamlesh.bar
Feb 6 '15 at 11:41













no success trying for same

– kamlesh.bar
Feb 6 '15 at 12:06







no success trying for same

– kamlesh.bar
Feb 6 '15 at 12:06






1




1





It seems to work by just modifying the paths in the index.php file, but I'm new to Laravel so obviously can't comment on whether this is stable / safe.

– user1537360
Feb 6 '15 at 13:06





It seems to work by just modifying the paths in the index.php file, but I'm new to Laravel so obviously can't comment on whether this is stable / safe.

– user1537360
Feb 6 '15 at 13:06













The other folders/files are supposed to be underneath your document root.

– Mike Rockétt
Feb 7 '15 at 18:04





The other folders/files are supposed to be underneath your document root.

– Mike Rockétt
Feb 7 '15 at 18:04












26 Answers
26






active

oldest

votes


















362














For Laravel 5:




  1. Rename server.php in your Laravel root folder to index.php

  2. Copy the .htaccess file from /public directory to your Laravel root
    folder.


That's it!






share|improve this answer





















  • 3





    you are welcome.. :) it also workes for Laravel 4.2

    – Asfaq Tamim
    Mar 4 '15 at 9:53






  • 81





    whatchout as this may be unsafe, make sure no one can't request your .env file if you're doing this unless you're ok with people viewing your database password in clear text ;)

    – GabLeRoux
    Mar 7 '15 at 3:35






  • 38





    This wouldn't work if you are referencing your assets using the relative path from root ie. "/assets/styles.css" and so on. I am still struggling with finding best way to deploy it over servers

    – Ghazanfar Mir
    Mar 17 '15 at 12:53






  • 3





    not working for me

    – Richie
    Apr 15 '15 at 14:21






  • 11





    all assets link not working with this method

    – Abdul Manan
    Apr 6 '17 at 20:29



















106














I have solved the issue using 2 answers:




  1. Renaming the server.php to index.php (no modifications)

  2. Copy the .htaccess from public folder to root folder
    (like rimon.ekjon said below)


  3. Changing .htaccess it a bit as follows for statics:



    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]


    If there are any other static files needed just add the extension to the previous declared list








share|improve this answer


























  • hello @KA_lin. How do I prevent someone from viewing .env like so localhost/oap/.env

    – Fokwa Best
    Dec 29 '15 at 10:26






  • 7





    Hmmm... try RewriteRule ^.env - [F,L,NC]

    – ka_lin
    Dec 29 '15 at 10:36






  • 1





    Or <Files ~ ".env$"> Order allow,deny Deny from all </Files>

    – ka_lin
    Dec 29 '15 at 10:37











  • Thanks a lot @ka_lin, is there any way to then remove access through /public/ ? like www.yoursite.com works but www.yoursite.com/public also works, is it possible to remove the last one ?

    – adaba
    Aug 23 '16 at 2:34






  • 6





    It is working but css, js and images are not loading

    – Chetan Khandla
    Mar 27 '17 at 11:19



















44














In Laravel 5.5 create .htacess file in your root directory and placed the following code:- Reference Link



<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>





share|improve this answer
























  • this is working great, but what about admin?

    – CagCak
    Mar 24 '18 at 12:03






  • 1





    the best answer! the only one worked in my example, it should have definitely more up votes

    – FiliusBonacci
    Apr 26 '18 at 14:27






  • 2





    Storage link doesn't work when using this code.

    – black_belt
    Jul 27 '18 at 5:32











  • Thanks this is work for me. But I want to know it has any security issue or not.

    – rahul singh Chauhan
    Aug 2 '18 at 5:58








  • 1





    What does this rule RewriteRule ^ ^$1 [N] do?

    – gonzo
    Sep 30 '18 at 10:02



















42














Easy way to remove public from laravel 5 url.
You just need to cut index.php and .htaccess from public directory and paste it in the root directory,thats all
and replace two lines in index.php as



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





share|improve this answer



















  • 1





    After that css not load, bcoz all css are in public and the public is removed from url

    – Tarzan
    Oct 1 '16 at 5:04






  • 1





    You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best solution would be virtual host...

    – Muhammad Sadiq
    Oct 3 '16 at 7:07



















35














@rimon.ekjon said:




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 :)



Thank you @rimon.ekjon and all of you.






share|improve this answer





















  • 2





    This is not a good way to resolve this problem, as you are trying to update in vendors directory which is not good practice.

    – Shadman
    Jan 25 '18 at 6:56






  • 1





    you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301]

    – Shadman
    Jan 25 '18 at 7:17





















23














1) I haven't found a working method for moving the public directory in L5. While you can modify some things in the bootstrap index.php, it appears several helper functions are based on the assumption of that public directory being there. In all honestly you really shouldn't be moving the public directory.



2) If your using MAMP then you should be creating new vhosts for each project, each serving that projects public directory. Once created you access each project by your defined server name like this :



http://project1.dev
http://project2.dev





share|improve this answer

































    19














    Just create .htaccess file at root and add these lines to it



    <IfModule mod_rewrite.c>
    RewriteEngine On

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


    That's it!



    The above code works on the root public_html folder. Having said that your core laravel file should be inside the public_html folder, if your directory looks like public_html/laravelapp/public and if you put the above code inside laravelapp it won't work. Therefore you must copy all your core files into public_html and put the .htaccess file there .



    If you want to keep the code in a subdirectory then you can create a subdomain then this code will work for that also.






    share|improve this answer


























    • I answered below before reading your answer and this must be the accepted answer. No file changes: just a simple, clever rule.

      – Brigo
      Jan 27 '18 at 17:40











    • @Raham what is your current url?

      – Abhinav Saraswat
      Feb 5 '18 at 6:30






    • 2





      Just want to add a short description on top of this gentlemen's work. The above code works on the root public_html folder (I had issues as well). Having said that your core laravel file should be inside public_html folder , i made a mistake that my directory looked like public_html/laravelapp/public if you put the above code inside laravelapp it wont work . Therefore you must copy all your core files into public_html and put the .htaccess file there . Referencing to centOS and Cpanel hosting for laravel.

      – Deepesh Thapa
      Apr 19 '18 at 21:23











    • What's the flaws with using this method?

      – Script47
      Oct 10 '18 at 23:40



















    14














    Even if the solution(s) mentioned in this thread works for you guys, I would request you not to do this. Here is the reason why.



    You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.



    The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.



    Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.



    If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory of public_html, do the same but create symlink from $LARAVEL_PATH/public to public_html/$PROJECT_SUBDIR.



    That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)






    share|improve this answer





















    • 2





      i accept your answer bcoz its secure for storage folder. Can you explain how to host the laravel app in shared hosting

      – Zaza
      Feb 19 '18 at 10:24








    • 1





      This really should be the accepted answer.

      – ceejayoz
      Oct 29 '18 at 15:03











    • @Zaza Sorry for late reply. To host laravel app in shared hosting, you can follow these steps dev.to/asapabedi/… Hope this helps.

      – Mittul At TechnoBrave
      Jan 16 at 4:43





















    12














    It's possible to remove public 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';


    And remove all cache and cookies.






    share|improve this answer


























    • Hi, I have tried your method, performed the above steps but it shows the following errors: Warning: require_once(D:Projectslaravel/public/index.php): failed to open stream: No such file or directory in D:Projectslaravelserver.php on line 21 Fatal error: require_once(): Failed opening required 'D:Projectslaravel/public/index.php' (include_path='.;C:xamppphpPEAR') in D:Projectslaravelserver.php on line 21

      – Ali Shahzad
      Mar 8 '15 at 7:26



















    11














    Let's say you placed all the other files and directories in a folder named 'locale'.



    enter image description here



    Just go to index.php and find these two lines:



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

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


    and change them to this:



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

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





    share|improve this answer

































      8














      BEST Approach:
      I will not recommend removing public, instead on local computer create a virtual host point to public directory and on remote hosting change public to public_html and point your domain to this directory. Reason, your whole laravel code will be secure because its one level down to your public directory :)



      METHOD 1:



      I just rename server.php to index.php and it works



      METHOD 2:



      This work well for all laravel version...



      Here is my Directory Structure,



      /laravel/
      ... app
      ... bootstrap
      ... public
      ... etc


      Follow these easy steps




      1. move all files from public directory to root /laravel/

      2. now, no need of public directory, so optionally you can remove it now

      3. now open index.php and make following replacements



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




      to




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




      and




      $app = require_once DIR.'/../bootstrap/start.php';




      to




      $app = require_once DIR.'/bootstrap/start.php';





      1. now open bootstrap/paths.php and change public directory path:



      'public' => DIR.'/../public',




      to




      'public' => DIR.'/..',




      and that's it, now try http:// localhost/laravel/






      share|improve this answer


























      • Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" . Is there any suggestion ?

        – Kabir Hossain
        Jan 29 '17 at 5:45













      • Thanks wasim a, Method 2 is working for me

        – Faridul Khan
        Nov 25 '17 at 12:02











      • This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env

        – MasoodUrRehman
        Dec 23 '17 at 14:43



















      6














      I would like to add to @Humble Learner and note that the proper location to "fix" the url path for assets is /Illuminate/Routing/UrlGenerator.php/asset().



      Update the method to match:



      public function asset($path, $secure = null)
      {
      if ($this->isValidUrl($path)) return $path;
      $root = $this->getRootUrl($this->getScheme($secure));
      return $this->removeIndex($root).'/public/'.trim($path, '/');
      }


      This will fix scripts, styles and image paths. Anything for asset paths.






      share|improve this answer































        4














        There is always a reason to have a public folder in the Laravel setup, all public related stuffs should be present inside the public folder,




        Don't Point your ip address/domain to the Laravel's root folder but point it to the public folder. It is unsafe pointing the server Ip to the root folder., because unless you write restrictions in .htaccess, one can easily access the other files.,




        Just write rewrite condition in the .htaccess file and install rewrite module and enable the rewrite module, the problem which adds public in the route will get solved.






        share|improve this answer



















        • 1





          You are correct .. Why we should break the things which framework is providing by default. We should try to understand the reason behind this before breaking this.

          – Mittul At TechnoBrave
          Sep 27 '17 at 11:13






        • 1





          I guess this answer should get more up-votes as it is suggesting users not to follow the steps which however are working as it will make security concerns by following those.

          – Mittul At TechnoBrave
          Sep 27 '17 at 11:40





















        4














        For XAMPP user to remove public from url without touching laravel default filesystem is to set a Virtual Host for your application to do this jsut follow these steps




        1. Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.


        2. Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.


        3. Open the file named httpd-vhosts.conf with a text editor.


        4. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.


        5. At the very bottom of the file paste the following code:



        <VirtualHost *>
        ServerAdmin admin@localhost.com
        DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
        ServerName localhost
        ServerAlias localhost
        <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        Order allow,deny
        Allow from all
        </Directory>
        </VirtualHost>



        1. Now you can copy and paste the code above below to add your Virtual Host directories. For example I’m working on a site called Eatery Engine so the following snippet will allow me to work with sub-domains on my local install:


        <VirtualHost eateryengine.dev>
        ServerAdmin admin@localhost.com
        DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your htdocs folder
        ServerName eateryengine.dev
        ServerAlias eateryengine.dev
        <Directory "C:/xampp/htdocs/eateryengine">
        Order allow,deny
        Allow from all
        </Directory>
        </VirtualHost>



        1. Next head over to your Windows host file to edit your HOSTS. the file will be located at C:/Windows/System32/drivers/etc/hosts, where hosts is the file. Open it with notepad.

        2. Look for #localhost name resolution is handled within DNS itself.


        127.0.0.1 localhost



        localhost name resolution is handled within DNS itself.



        127.0.0.1       localhost
        127.0.0.1 eateryengine.dev #change to match your Virtual Host.
        127.0.0.1 demo.eateryengine.dev #manually add new sub-domains.



        1. Restart Apache and test everything.


        The original article can be found here






        share|improve this answer

































          4














          Here is the Best and shortest solution that works for me as of may, 2018
          for Laravel 5.5



          1- just cut your .htaccess file from the /public directory to the root directory and replace it content with the following code:



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

          RewriteEngine On

          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)/$ /$1 [L,R=301]

          RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule ^ server.php [L]

          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_URI} !^/public/
          RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

          </IfModule>


          2- Just save the .htaccess file and that is all.



          3- Rename your server.php file to index.php. that is all enjoy!






          share|improve this answer

































            2














            Firstly you can use this steps




            For Laravel 5:



            1. Rename server.php in your Laravel root folder to index.php



            2. Copy the .htaccess file from /public directory to your Laravel root folder.




            source: https://stackoverflow.com/a/28735930



            after you follow these steps then you need to change all css and script path, but this will be tiring.



            Solution Proposal :simply you can make minor change the helpers::asset function.



            For this:




            1. open vendorlaravelframeworksrcIlluminateFoundationhelpers.php


            2. goto line 130



            3. write "public/".$path instead of $path,



              function asset($path, $secure = null){
              return app('url')->asset("public/".$path, $secure);
              }







            share|improve this answer





















            • 1





              Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.

              – Janaka Dombawela
              Nov 9 '18 at 10:48













            • @JanakaDombawela i don't think that way because:

              – Ferhat KOÇER
              Dec 13 '18 at 19:32











            • @JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain experience

              – Ferhat KOÇER
              Dec 13 '18 at 19:39





















            2














            Don't:



            You really should not rename server.php in your Laravel root folder to index.php
            and copy the .htaccess file from /public directory to your Laravel root folder!



            This way everyone can access some of your files (.env for example). You don't want that!





            Do:



            Instead, you should create a .htaccess file in your root like this:



            RewriteEngine On
            RewriteCond %{REQUEST_URI} !^/public/
            RewriteRule ^(.*)$ /public/$1 [L,QSA]


            That's it.






            share|improve this answer



















            • 1





              this works for me. thanks bro. you saved my day

              – Emtiaz Zahid
              Jan 5 at 9:46






            • 1





              It worked best with Lumen on Apache server.

              – Almas Dusal
              Jan 24 at 1:50



















            1














            Another method that I use is to create a symbolic link (in Linux, don't know about Win) using the ln command in htdocs or www i.e. ln projectname/public project
            The site is thus accessible via localhost/project






            share|improve this answer































              1














              I have read some article before and it's working fine but really don't know is safe or not



                  a. Create new folder local.
              b. Move all project into the local folder expect public folder.
              c. Move all the content of public folder to project root.
              d. Delete the blank public folder
              f. Edit the index file.


              Edit the index.php



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


              to



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





              share|improve this answer































                1














                Even if i do not recommend putting Laravel on the root folder there are some cases when it could not be avoided;
                for those cases the above methods do not work for assets so i made a quick fix changing the htaccess:
                after copying server.php to index.php edit the .htaccess file like so:



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

                RewriteEngine On

                ### fix file rewrites on root path ###
                #select file url
                RewriteCond %{REQUEST_URI} ^(.*)$
                #if file exists in /public/<filename>
                RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
                #redirect to /public/<filename>
                RewriteRule ^(.*)$ public/$1 [L]
                ###############

                # Redirect Trailing Slashes If Not A Folder...
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)/$ /$1 [L,R=301]

                # Handle Front Controller...

                #RewriteCond %{REQUEST_FILENAME} -d # comment this rules or the user will read non-public file and folders!
                #RewriteCond %{REQUEST_FILENAME} -f #
                RewriteRule ^ index.php [L]
                </IfModule>


                This was a quick fix i had to make so anyone is welcome to upgrade it.






                share|improve this answer































                  1














                  Laravel 5.5



                  After having installed Laravel for the first time, I faced the renowned "public folder problem" and I came up with this solution that, in my personal opinion, is "cleaner" then the others I found on the Web.





                  Achievements




                  • Don't have public word in the URI

                  • Protect the .env file against curious people


                  Everything can be done just editing the .htaccess using mod_rewrite and four simple rules.





                  Steps




                  1. Move the .htaccess file in public/.htaccess in the main root

                  2. Edit it as below


                  I commented everything, so it should be clear (I hope) also to those who have never used mod_rewrite (not that I'm an expert, all the opposite). Also, to understand the rules, it must be clear that, in Laravel, if Bill connects to https://example.com, https://example.com/index.php is loaded. This file just contains the command header("refresh: 5; https://example.com/public/"), which sends the request to https://example.com/public/index.php. This second index.php is responsible to load the controller and other stuff.



                  # IfModule prevents the server error if the app is moved in an environment which doesn’t support mod_rewrite
                  <IfModule mod_rewrite.c>
                  <IfModule mod_negotiation.c>
                  Options -MultiViews
                  </IfModule>

                  RewriteEngine On

                  # RULES ORIGINALLY IN public/.htaccess ---
                  # Redirect Trailing Slashes If Not A Folder...
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteCond %{REQUEST_URI} (.+)/$
                  RewriteRule ^ %1 [L,R=301]

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

                  # Handle Authorization Header
                  RewriteCond %{HTTP:Authorization} .
                  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
                  # --- END

                  # PERSONAL RULES ---
                  # All the requests on port 80 are redirected on HTTPS
                  RewriteCond %{SERVER_PORT} ^80$
                  RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

                  # When .env file is requested, server redirects to 404
                  RewriteRule ^.env$ - [R=404,L,NC]

                  # If the REQUEST_URI is empty (means: http://example.com), it loads /public/index.php
                  # N.B.: REQUEST_URI is *never* actually empty, it contains a slash that must be set as match as below
                  # .* means: anything can go here at least 0 times (= accepts any sequence of characters, including an empty string)
                  RewriteCond %{REQUEST_URI} ^/$
                  RewriteRule ^(.*) /public/index.php [L]

                  # If the current request is asking for a REQUEST_FILENAME that:
                  # a) !== existent directory
                  # b) !== existent file
                  # => if URI !== css||js||images/whatever => server loads /public/index.php, which is responsible to load the app and the related controller
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteRule !^(css|js|images|media)/(.*)$ /public/index.php [L,NC]

                  # If the current request is asking for a REQUEST_FILENAME that:
                  # a) !== existent directory
                  # b) !== existent file
                  # => if URI == css||js||images[=$1]/whatever[=$2] => server loads the resource at public/$1/$2
                  # If R flag is added, the server not only loads the resource at public/$1/$2 but redirects to it
                  # e.g.: bamboo.jpg resides in example.com/public/media/bamboo.jpg
                  # Client asks for example.com/media/bamboo.jpg
                  # Without R flag: the URI remains example.com/media/bamboo.jpg and loads the image
                  # With R flag: the server redirects the client to example.com/public/media/bamboo.jpg and loads the image
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]
                  # --- END

                  </IfModule>


                  The following rule (originally in public/.htaccess) can be deleted. The same rule, in fact, is explicited in a more detailed way in the last two rules.



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




                  EDIT: I missed Abhinav Saraswat's solution and his answer should be the accepted one. Just one, simple and clear rule that redirects all the traffic to the public folder without modifying any file.






                  share|improve this answer

































                    0














                     You can follow only 2 step


                    1- cut .htaccess from public folder and paste to root(mainFolder)
                    2- Rename server.php file to index.php AT your root dir. (mainFolder)





                    share|improve this answer































                      0














                      step 1:
                      server.php file in root directory rename as index.php



                      step 2:



                      copy .htaccess file from public directory to root direct






                      share|improve this answer


























                      • server.php is not in the public folder. It is already in the root you just have to rename it.

                        – Muhammad Wajahat Anwar
                        Mar 2 '18 at 18:55











                      • @MuhammadWajahatAnwar ya you right . i correct this

                        – Ravindra Bhanderi
                        Mar 3 '18 at 18:18



















                      0














                      You can remove public keyword from url using various methods.



                      1) If you are using dedicated hosting and you have root access then You can remove public keyword from url using Virtual Host. You should give DocumentRoot path with public. So this will start index from public directory and remove it from url.



                      <VirtualHost *:80>
                      ServerAdmin info@example.com
                      ServerName example.com
                      ServerAlias www.example.com
                      DocumentRoot /var/www/html/{yoursourcedirectory}/public

                      ErrorLog ${APACHE_LOG_DIR}/error.log
                      CustomLog ${APACHE_LOG_DIR}/access.log combined
                      </VirtualHost>


                      2) If you dont have root access of your hosting then you should genarate a new .htaccess file in your root directory and put the code as below



                      <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>


                      You can get more reference here.






                      share|improve this answer































                        0














                        I found the most working solution for this problem. Just edit your .htaccess in root folder and write the following code. Nothing else required



                          RewriteEngine on
                        RewriteCond %{REQUEST_URI} !^public
                        RewriteRule ^(.*)$ public/$1 [L]

                        <IfModule php7_module>
                        php_flag display_errors Off
                        php_value max_execution_time 30
                        php_value max_input_time 60
                        php_value max_input_vars 1000
                        php_value memory_limit -1
                        php_value post_max_size 8M
                        php_value session.gc_maxlifetime 1440
                        php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
                        php_value upload_max_filesize 2M
                        php_flag zlib.output_compression Off
                        </IfModule>





                        share|improve this answer































                          0














                          ##Create .htaccess file in root directory and place code something like below.

                          <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>





                          share|improve this answer






















                            protected by Community Mar 11 '16 at 5:30



                            Thank you for your interest in this question.
                            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                            Would you like to answer one of these unanswered questions instead?














                            26 Answers
                            26






                            active

                            oldest

                            votes








                            26 Answers
                            26






                            active

                            oldest

                            votes









                            active

                            oldest

                            votes






                            active

                            oldest

                            votes









                            362














                            For Laravel 5:




                            1. Rename server.php in your Laravel root folder to index.php

                            2. Copy the .htaccess file from /public directory to your Laravel root
                              folder.


                            That's it!






                            share|improve this answer





















                            • 3





                              you are welcome.. :) it also workes for Laravel 4.2

                              – Asfaq Tamim
                              Mar 4 '15 at 9:53






                            • 81





                              whatchout as this may be unsafe, make sure no one can't request your .env file if you're doing this unless you're ok with people viewing your database password in clear text ;)

                              – GabLeRoux
                              Mar 7 '15 at 3:35






                            • 38





                              This wouldn't work if you are referencing your assets using the relative path from root ie. "/assets/styles.css" and so on. I am still struggling with finding best way to deploy it over servers

                              – Ghazanfar Mir
                              Mar 17 '15 at 12:53






                            • 3





                              not working for me

                              – Richie
                              Apr 15 '15 at 14:21






                            • 11





                              all assets link not working with this method

                              – Abdul Manan
                              Apr 6 '17 at 20:29
















                            362














                            For Laravel 5:




                            1. Rename server.php in your Laravel root folder to index.php

                            2. Copy the .htaccess file from /public directory to your Laravel root
                              folder.


                            That's it!






                            share|improve this answer





















                            • 3





                              you are welcome.. :) it also workes for Laravel 4.2

                              – Asfaq Tamim
                              Mar 4 '15 at 9:53






                            • 81





                              whatchout as this may be unsafe, make sure no one can't request your .env file if you're doing this unless you're ok with people viewing your database password in clear text ;)

                              – GabLeRoux
                              Mar 7 '15 at 3:35






                            • 38





                              This wouldn't work if you are referencing your assets using the relative path from root ie. "/assets/styles.css" and so on. I am still struggling with finding best way to deploy it over servers

                              – Ghazanfar Mir
                              Mar 17 '15 at 12:53






                            • 3





                              not working for me

                              – Richie
                              Apr 15 '15 at 14:21






                            • 11





                              all assets link not working with this method

                              – Abdul Manan
                              Apr 6 '17 at 20:29














                            362












                            362








                            362







                            For Laravel 5:




                            1. Rename server.php in your Laravel root folder to index.php

                            2. Copy the .htaccess file from /public directory to your Laravel root
                              folder.


                            That's it!






                            share|improve this answer















                            For Laravel 5:




                            1. Rename server.php in your Laravel root folder to index.php

                            2. Copy the .htaccess file from /public directory to your Laravel root
                              folder.


                            That's it!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 20 '18 at 12:22









                            Prakash Pazhanisamy

                            8681923




                            8681923










                            answered Feb 26 '15 at 6:32









                            Asfaq TamimAsfaq Tamim

                            4,15541526




                            4,15541526








                            • 3





                              you are welcome.. :) it also workes for Laravel 4.2

                              – Asfaq Tamim
                              Mar 4 '15 at 9:53






                            • 81





                              whatchout as this may be unsafe, make sure no one can't request your .env file if you're doing this unless you're ok with people viewing your database password in clear text ;)

                              – GabLeRoux
                              Mar 7 '15 at 3:35






                            • 38





                              This wouldn't work if you are referencing your assets using the relative path from root ie. "/assets/styles.css" and so on. I am still struggling with finding best way to deploy it over servers

                              – Ghazanfar Mir
                              Mar 17 '15 at 12:53






                            • 3





                              not working for me

                              – Richie
                              Apr 15 '15 at 14:21






                            • 11





                              all assets link not working with this method

                              – Abdul Manan
                              Apr 6 '17 at 20:29














                            • 3





                              you are welcome.. :) it also workes for Laravel 4.2

                              – Asfaq Tamim
                              Mar 4 '15 at 9:53






                            • 81





                              whatchout as this may be unsafe, make sure no one can't request your .env file if you're doing this unless you're ok with people viewing your database password in clear text ;)

                              – GabLeRoux
                              Mar 7 '15 at 3:35






                            • 38





                              This wouldn't work if you are referencing your assets using the relative path from root ie. "/assets/styles.css" and so on. I am still struggling with finding best way to deploy it over servers

                              – Ghazanfar Mir
                              Mar 17 '15 at 12:53






                            • 3





                              not working for me

                              – Richie
                              Apr 15 '15 at 14:21






                            • 11





                              all assets link not working with this method

                              – Abdul Manan
                              Apr 6 '17 at 20:29








                            3




                            3





                            you are welcome.. :) it also workes for Laravel 4.2

                            – Asfaq Tamim
                            Mar 4 '15 at 9:53





                            you are welcome.. :) it also workes for Laravel 4.2

                            – Asfaq Tamim
                            Mar 4 '15 at 9:53




                            81




                            81





                            whatchout as this may be unsafe, make sure no one can't request your .env file if you're doing this unless you're ok with people viewing your database password in clear text ;)

                            – GabLeRoux
                            Mar 7 '15 at 3:35





                            whatchout as this may be unsafe, make sure no one can't request your .env file if you're doing this unless you're ok with people viewing your database password in clear text ;)

                            – GabLeRoux
                            Mar 7 '15 at 3:35




                            38




                            38





                            This wouldn't work if you are referencing your assets using the relative path from root ie. "/assets/styles.css" and so on. I am still struggling with finding best way to deploy it over servers

                            – Ghazanfar Mir
                            Mar 17 '15 at 12:53





                            This wouldn't work if you are referencing your assets using the relative path from root ie. "/assets/styles.css" and so on. I am still struggling with finding best way to deploy it over servers

                            – Ghazanfar Mir
                            Mar 17 '15 at 12:53




                            3




                            3





                            not working for me

                            – Richie
                            Apr 15 '15 at 14:21





                            not working for me

                            – Richie
                            Apr 15 '15 at 14:21




                            11




                            11





                            all assets link not working with this method

                            – Abdul Manan
                            Apr 6 '17 at 20:29





                            all assets link not working with this method

                            – Abdul Manan
                            Apr 6 '17 at 20:29













                            106














                            I have solved the issue using 2 answers:




                            1. Renaming the server.php to index.php (no modifications)

                            2. Copy the .htaccess from public folder to root folder
                              (like rimon.ekjon said below)


                            3. Changing .htaccess it a bit as follows for statics:



                              RewriteEngine On

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteRule ^(.*)/$ /$1 [L,R=301]

                              RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteRule ^ index.php [L]

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteCond %{REQUEST_URI} !^/public/
                              RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]


                              If there are any other static files needed just add the extension to the previous declared list








                            share|improve this answer


























                            • hello @KA_lin. How do I prevent someone from viewing .env like so localhost/oap/.env

                              – Fokwa Best
                              Dec 29 '15 at 10:26






                            • 7





                              Hmmm... try RewriteRule ^.env - [F,L,NC]

                              – ka_lin
                              Dec 29 '15 at 10:36






                            • 1





                              Or <Files ~ ".env$"> Order allow,deny Deny from all </Files>

                              – ka_lin
                              Dec 29 '15 at 10:37











                            • Thanks a lot @ka_lin, is there any way to then remove access through /public/ ? like www.yoursite.com works but www.yoursite.com/public also works, is it possible to remove the last one ?

                              – adaba
                              Aug 23 '16 at 2:34






                            • 6





                              It is working but css, js and images are not loading

                              – Chetan Khandla
                              Mar 27 '17 at 11:19
















                            106














                            I have solved the issue using 2 answers:




                            1. Renaming the server.php to index.php (no modifications)

                            2. Copy the .htaccess from public folder to root folder
                              (like rimon.ekjon said below)


                            3. Changing .htaccess it a bit as follows for statics:



                              RewriteEngine On

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteRule ^(.*)/$ /$1 [L,R=301]

                              RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteRule ^ index.php [L]

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteCond %{REQUEST_URI} !^/public/
                              RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]


                              If there are any other static files needed just add the extension to the previous declared list








                            share|improve this answer


























                            • hello @KA_lin. How do I prevent someone from viewing .env like so localhost/oap/.env

                              – Fokwa Best
                              Dec 29 '15 at 10:26






                            • 7





                              Hmmm... try RewriteRule ^.env - [F,L,NC]

                              – ka_lin
                              Dec 29 '15 at 10:36






                            • 1





                              Or <Files ~ ".env$"> Order allow,deny Deny from all </Files>

                              – ka_lin
                              Dec 29 '15 at 10:37











                            • Thanks a lot @ka_lin, is there any way to then remove access through /public/ ? like www.yoursite.com works but www.yoursite.com/public also works, is it possible to remove the last one ?

                              – adaba
                              Aug 23 '16 at 2:34






                            • 6





                              It is working but css, js and images are not loading

                              – Chetan Khandla
                              Mar 27 '17 at 11:19














                            106












                            106








                            106







                            I have solved the issue using 2 answers:




                            1. Renaming the server.php to index.php (no modifications)

                            2. Copy the .htaccess from public folder to root folder
                              (like rimon.ekjon said below)


                            3. Changing .htaccess it a bit as follows for statics:



                              RewriteEngine On

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteRule ^(.*)/$ /$1 [L,R=301]

                              RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteRule ^ index.php [L]

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteCond %{REQUEST_URI} !^/public/
                              RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]


                              If there are any other static files needed just add the extension to the previous declared list








                            share|improve this answer















                            I have solved the issue using 2 answers:




                            1. Renaming the server.php to index.php (no modifications)

                            2. Copy the .htaccess from public folder to root folder
                              (like rimon.ekjon said below)


                            3. Changing .htaccess it a bit as follows for statics:



                              RewriteEngine On

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteRule ^(.*)/$ /$1 [L,R=301]

                              RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteRule ^ index.php [L]

                              RewriteCond %{REQUEST_FILENAME} !-d
                              RewriteCond %{REQUEST_FILENAME} !-f
                              RewriteCond %{REQUEST_URI} !^/public/
                              RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]


                              If there are any other static files needed just add the extension to the previous declared list









                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 16 '17 at 20:13









                            Mian Haseeb

                            12617




                            12617










                            answered Sep 15 '15 at 7:57









                            ka_linka_lin

                            6,50042743




                            6,50042743













                            • hello @KA_lin. How do I prevent someone from viewing .env like so localhost/oap/.env

                              – Fokwa Best
                              Dec 29 '15 at 10:26






                            • 7





                              Hmmm... try RewriteRule ^.env - [F,L,NC]

                              – ka_lin
                              Dec 29 '15 at 10:36






                            • 1





                              Or <Files ~ ".env$"> Order allow,deny Deny from all </Files>

                              – ka_lin
                              Dec 29 '15 at 10:37











                            • Thanks a lot @ka_lin, is there any way to then remove access through /public/ ? like www.yoursite.com works but www.yoursite.com/public also works, is it possible to remove the last one ?

                              – adaba
                              Aug 23 '16 at 2:34






                            • 6





                              It is working but css, js and images are not loading

                              – Chetan Khandla
                              Mar 27 '17 at 11:19



















                            • hello @KA_lin. How do I prevent someone from viewing .env like so localhost/oap/.env

                              – Fokwa Best
                              Dec 29 '15 at 10:26






                            • 7





                              Hmmm... try RewriteRule ^.env - [F,L,NC]

                              – ka_lin
                              Dec 29 '15 at 10:36






                            • 1





                              Or <Files ~ ".env$"> Order allow,deny Deny from all </Files>

                              – ka_lin
                              Dec 29 '15 at 10:37











                            • Thanks a lot @ka_lin, is there any way to then remove access through /public/ ? like www.yoursite.com works but www.yoursite.com/public also works, is it possible to remove the last one ?

                              – adaba
                              Aug 23 '16 at 2:34






                            • 6





                              It is working but css, js and images are not loading

                              – Chetan Khandla
                              Mar 27 '17 at 11:19

















                            hello @KA_lin. How do I prevent someone from viewing .env like so localhost/oap/.env

                            – Fokwa Best
                            Dec 29 '15 at 10:26





                            hello @KA_lin. How do I prevent someone from viewing .env like so localhost/oap/.env

                            – Fokwa Best
                            Dec 29 '15 at 10:26




                            7




                            7





                            Hmmm... try RewriteRule ^.env - [F,L,NC]

                            – ka_lin
                            Dec 29 '15 at 10:36





                            Hmmm... try RewriteRule ^.env - [F,L,NC]

                            – ka_lin
                            Dec 29 '15 at 10:36




                            1




                            1





                            Or <Files ~ ".env$"> Order allow,deny Deny from all </Files>

                            – ka_lin
                            Dec 29 '15 at 10:37





                            Or <Files ~ ".env$"> Order allow,deny Deny from all </Files>

                            – ka_lin
                            Dec 29 '15 at 10:37













                            Thanks a lot @ka_lin, is there any way to then remove access through /public/ ? like www.yoursite.com works but www.yoursite.com/public also works, is it possible to remove the last one ?

                            – adaba
                            Aug 23 '16 at 2:34





                            Thanks a lot @ka_lin, is there any way to then remove access through /public/ ? like www.yoursite.com works but www.yoursite.com/public also works, is it possible to remove the last one ?

                            – adaba
                            Aug 23 '16 at 2:34




                            6




                            6





                            It is working but css, js and images are not loading

                            – Chetan Khandla
                            Mar 27 '17 at 11:19





                            It is working but css, js and images are not loading

                            – Chetan Khandla
                            Mar 27 '17 at 11:19











                            44














                            In Laravel 5.5 create .htacess file in your root directory and placed the following code:- Reference Link



                            <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>





                            share|improve this answer
























                            • this is working great, but what about admin?

                              – CagCak
                              Mar 24 '18 at 12:03






                            • 1





                              the best answer! the only one worked in my example, it should have definitely more up votes

                              – FiliusBonacci
                              Apr 26 '18 at 14:27






                            • 2





                              Storage link doesn't work when using this code.

                              – black_belt
                              Jul 27 '18 at 5:32











                            • Thanks this is work for me. But I want to know it has any security issue or not.

                              – rahul singh Chauhan
                              Aug 2 '18 at 5:58








                            • 1





                              What does this rule RewriteRule ^ ^$1 [N] do?

                              – gonzo
                              Sep 30 '18 at 10:02
















                            44














                            In Laravel 5.5 create .htacess file in your root directory and placed the following code:- Reference Link



                            <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>





                            share|improve this answer
























                            • this is working great, but what about admin?

                              – CagCak
                              Mar 24 '18 at 12:03






                            • 1





                              the best answer! the only one worked in my example, it should have definitely more up votes

                              – FiliusBonacci
                              Apr 26 '18 at 14:27






                            • 2





                              Storage link doesn't work when using this code.

                              – black_belt
                              Jul 27 '18 at 5:32











                            • Thanks this is work for me. But I want to know it has any security issue or not.

                              – rahul singh Chauhan
                              Aug 2 '18 at 5:58








                            • 1





                              What does this rule RewriteRule ^ ^$1 [N] do?

                              – gonzo
                              Sep 30 '18 at 10:02














                            44












                            44








                            44







                            In Laravel 5.5 create .htacess file in your root directory and placed the following code:- Reference Link



                            <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>





                            share|improve this answer













                            In Laravel 5.5 create .htacess file in your root directory and placed the following code:- Reference Link



                            <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>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 29 '18 at 4:11









                            RahamRaham

                            2,13411624




                            2,13411624













                            • this is working great, but what about admin?

                              – CagCak
                              Mar 24 '18 at 12:03






                            • 1





                              the best answer! the only one worked in my example, it should have definitely more up votes

                              – FiliusBonacci
                              Apr 26 '18 at 14:27






                            • 2





                              Storage link doesn't work when using this code.

                              – black_belt
                              Jul 27 '18 at 5:32











                            • Thanks this is work for me. But I want to know it has any security issue or not.

                              – rahul singh Chauhan
                              Aug 2 '18 at 5:58








                            • 1





                              What does this rule RewriteRule ^ ^$1 [N] do?

                              – gonzo
                              Sep 30 '18 at 10:02



















                            • this is working great, but what about admin?

                              – CagCak
                              Mar 24 '18 at 12:03






                            • 1





                              the best answer! the only one worked in my example, it should have definitely more up votes

                              – FiliusBonacci
                              Apr 26 '18 at 14:27






                            • 2





                              Storage link doesn't work when using this code.

                              – black_belt
                              Jul 27 '18 at 5:32











                            • Thanks this is work for me. But I want to know it has any security issue or not.

                              – rahul singh Chauhan
                              Aug 2 '18 at 5:58








                            • 1





                              What does this rule RewriteRule ^ ^$1 [N] do?

                              – gonzo
                              Sep 30 '18 at 10:02

















                            this is working great, but what about admin?

                            – CagCak
                            Mar 24 '18 at 12:03





                            this is working great, but what about admin?

                            – CagCak
                            Mar 24 '18 at 12:03




                            1




                            1





                            the best answer! the only one worked in my example, it should have definitely more up votes

                            – FiliusBonacci
                            Apr 26 '18 at 14:27





                            the best answer! the only one worked in my example, it should have definitely more up votes

                            – FiliusBonacci
                            Apr 26 '18 at 14:27




                            2




                            2





                            Storage link doesn't work when using this code.

                            – black_belt
                            Jul 27 '18 at 5:32





                            Storage link doesn't work when using this code.

                            – black_belt
                            Jul 27 '18 at 5:32













                            Thanks this is work for me. But I want to know it has any security issue or not.

                            – rahul singh Chauhan
                            Aug 2 '18 at 5:58







                            Thanks this is work for me. But I want to know it has any security issue or not.

                            – rahul singh Chauhan
                            Aug 2 '18 at 5:58






                            1




                            1





                            What does this rule RewriteRule ^ ^$1 [N] do?

                            – gonzo
                            Sep 30 '18 at 10:02





                            What does this rule RewriteRule ^ ^$1 [N] do?

                            – gonzo
                            Sep 30 '18 at 10:02











                            42














                            Easy way to remove public from laravel 5 url.
                            You just need to cut index.php and .htaccess from public directory and paste it in the root directory,thats all
                            and replace two lines in index.php as



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





                            share|improve this answer



















                            • 1





                              After that css not load, bcoz all css are in public and the public is removed from url

                              – Tarzan
                              Oct 1 '16 at 5:04






                            • 1





                              You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best solution would be virtual host...

                              – Muhammad Sadiq
                              Oct 3 '16 at 7:07
















                            42














                            Easy way to remove public from laravel 5 url.
                            You just need to cut index.php and .htaccess from public directory and paste it in the root directory,thats all
                            and replace two lines in index.php as



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





                            share|improve this answer



















                            • 1





                              After that css not load, bcoz all css are in public and the public is removed from url

                              – Tarzan
                              Oct 1 '16 at 5:04






                            • 1





                              You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best solution would be virtual host...

                              – Muhammad Sadiq
                              Oct 3 '16 at 7:07














                            42












                            42








                            42







                            Easy way to remove public from laravel 5 url.
                            You just need to cut index.php and .htaccess from public directory and paste it in the root directory,thats all
                            and replace two lines in index.php as



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





                            share|improve this answer













                            Easy way to remove public from laravel 5 url.
                            You just need to cut index.php and .htaccess from public directory and paste it in the root directory,thats all
                            and replace two lines in index.php as



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






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 29 '15 at 11:00









                            Muhammad SadiqMuhammad Sadiq

                            972109




                            972109








                            • 1





                              After that css not load, bcoz all css are in public and the public is removed from url

                              – Tarzan
                              Oct 1 '16 at 5:04






                            • 1





                              You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best solution would be virtual host...

                              – Muhammad Sadiq
                              Oct 3 '16 at 7:07














                            • 1





                              After that css not load, bcoz all css are in public and the public is removed from url

                              – Tarzan
                              Oct 1 '16 at 5:04






                            • 1





                              You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best solution would be virtual host...

                              – Muhammad Sadiq
                              Oct 3 '16 at 7:07








                            1




                            1





                            After that css not load, bcoz all css are in public and the public is removed from url

                            – Tarzan
                            Oct 1 '16 at 5:04





                            After that css not load, bcoz all css are in public and the public is removed from url

                            – Tarzan
                            Oct 1 '16 at 5:04




                            1




                            1





                            You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best solution would be virtual host...

                            – Muhammad Sadiq
                            Oct 3 '16 at 7:07





                            You can put "public/" before the js or css files while loading, eg Html::script("public/js/....."); --But the best solution would be virtual host...

                            – Muhammad Sadiq
                            Oct 3 '16 at 7:07











                            35














                            @rimon.ekjon said:




                            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 :)



                            Thank you @rimon.ekjon and all of you.






                            share|improve this answer





















                            • 2





                              This is not a good way to resolve this problem, as you are trying to update in vendors directory which is not good practice.

                              – Shadman
                              Jan 25 '18 at 6:56






                            • 1





                              you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301]

                              – Shadman
                              Jan 25 '18 at 7:17


















                            35














                            @rimon.ekjon said:




                            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 :)



                            Thank you @rimon.ekjon and all of you.






                            share|improve this answer





















                            • 2





                              This is not a good way to resolve this problem, as you are trying to update in vendors directory which is not good practice.

                              – Shadman
                              Jan 25 '18 at 6:56






                            • 1





                              you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301]

                              – Shadman
                              Jan 25 '18 at 7:17
















                            35












                            35








                            35







                            @rimon.ekjon said:




                            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 :)



                            Thank you @rimon.ekjon and all of you.






                            share|improve this answer















                            @rimon.ekjon said:




                            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 :)



                            Thank you @rimon.ekjon and all of you.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Sep 11 '15 at 9:22

























                            answered Sep 11 '15 at 9:16









                            MironMiron

                            6831022




                            6831022








                            • 2





                              This is not a good way to resolve this problem, as you are trying to update in vendors directory which is not good practice.

                              – Shadman
                              Jan 25 '18 at 6:56






                            • 1





                              you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301]

                              – Shadman
                              Jan 25 '18 at 7:17
















                            • 2





                              This is not a good way to resolve this problem, as you are trying to update in vendors directory which is not good practice.

                              – Shadman
                              Jan 25 '18 at 6:56






                            • 1





                              you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301]

                              – Shadman
                              Jan 25 '18 at 7:17










                            2




                            2





                            This is not a good way to resolve this problem, as you are trying to update in vendors directory which is not good practice.

                            – Shadman
                            Jan 25 '18 at 6:56





                            This is not a good way to resolve this problem, as you are trying to update in vendors directory which is not good practice.

                            – Shadman
                            Jan 25 '18 at 6:56




                            1




                            1





                            you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301]

                            – Shadman
                            Jan 25 '18 at 7:17







                            you only need to add RewriteRule ^(.*)$ public/$1 [L] in your .htaccess file which you have copied from public directory, by removing this line RewriteRule ^(.*)/$ /$1 [L,R=301]

                            – Shadman
                            Jan 25 '18 at 7:17













                            23














                            1) I haven't found a working method for moving the public directory in L5. While you can modify some things in the bootstrap index.php, it appears several helper functions are based on the assumption of that public directory being there. In all honestly you really shouldn't be moving the public directory.



                            2) If your using MAMP then you should be creating new vhosts for each project, each serving that projects public directory. Once created you access each project by your defined server name like this :



                            http://project1.dev
                            http://project2.dev





                            share|improve this answer






























                              23














                              1) I haven't found a working method for moving the public directory in L5. While you can modify some things in the bootstrap index.php, it appears several helper functions are based on the assumption of that public directory being there. In all honestly you really shouldn't be moving the public directory.



                              2) If your using MAMP then you should be creating new vhosts for each project, each serving that projects public directory. Once created you access each project by your defined server name like this :



                              http://project1.dev
                              http://project2.dev





                              share|improve this answer




























                                23












                                23








                                23







                                1) I haven't found a working method for moving the public directory in L5. While you can modify some things in the bootstrap index.php, it appears several helper functions are based on the assumption of that public directory being there. In all honestly you really shouldn't be moving the public directory.



                                2) If your using MAMP then you should be creating new vhosts for each project, each serving that projects public directory. Once created you access each project by your defined server name like this :



                                http://project1.dev
                                http://project2.dev





                                share|improve this answer















                                1) I haven't found a working method for moving the public directory in L5. While you can modify some things in the bootstrap index.php, it appears several helper functions are based on the assumption of that public directory being there. In all honestly you really shouldn't be moving the public directory.



                                2) If your using MAMP then you should be creating new vhosts for each project, each serving that projects public directory. Once created you access each project by your defined server name like this :



                                http://project1.dev
                                http://project2.dev






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Dec 28 '18 at 19:51









                                Jignesh Joisar

                                2,66511021




                                2,66511021










                                answered Feb 8 '15 at 1:38









                                Jeremy SchafferJeremy Schaffer

                                37327




                                37327























                                    19














                                    Just create .htaccess file at root and add these lines to it



                                    <IfModule mod_rewrite.c>
                                    RewriteEngine On

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


                                    That's it!



                                    The above code works on the root public_html folder. Having said that your core laravel file should be inside the public_html folder, if your directory looks like public_html/laravelapp/public and if you put the above code inside laravelapp it won't work. Therefore you must copy all your core files into public_html and put the .htaccess file there .



                                    If you want to keep the code in a subdirectory then you can create a subdomain then this code will work for that also.






                                    share|improve this answer


























                                    • I answered below before reading your answer and this must be the accepted answer. No file changes: just a simple, clever rule.

                                      – Brigo
                                      Jan 27 '18 at 17:40











                                    • @Raham what is your current url?

                                      – Abhinav Saraswat
                                      Feb 5 '18 at 6:30






                                    • 2





                                      Just want to add a short description on top of this gentlemen's work. The above code works on the root public_html folder (I had issues as well). Having said that your core laravel file should be inside public_html folder , i made a mistake that my directory looked like public_html/laravelapp/public if you put the above code inside laravelapp it wont work . Therefore you must copy all your core files into public_html and put the .htaccess file there . Referencing to centOS and Cpanel hosting for laravel.

                                      – Deepesh Thapa
                                      Apr 19 '18 at 21:23











                                    • What's the flaws with using this method?

                                      – Script47
                                      Oct 10 '18 at 23:40
















                                    19














                                    Just create .htaccess file at root and add these lines to it



                                    <IfModule mod_rewrite.c>
                                    RewriteEngine On

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


                                    That's it!



                                    The above code works on the root public_html folder. Having said that your core laravel file should be inside the public_html folder, if your directory looks like public_html/laravelapp/public and if you put the above code inside laravelapp it won't work. Therefore you must copy all your core files into public_html and put the .htaccess file there .



                                    If you want to keep the code in a subdirectory then you can create a subdomain then this code will work for that also.






                                    share|improve this answer


























                                    • I answered below before reading your answer and this must be the accepted answer. No file changes: just a simple, clever rule.

                                      – Brigo
                                      Jan 27 '18 at 17:40











                                    • @Raham what is your current url?

                                      – Abhinav Saraswat
                                      Feb 5 '18 at 6:30






                                    • 2





                                      Just want to add a short description on top of this gentlemen's work. The above code works on the root public_html folder (I had issues as well). Having said that your core laravel file should be inside public_html folder , i made a mistake that my directory looked like public_html/laravelapp/public if you put the above code inside laravelapp it wont work . Therefore you must copy all your core files into public_html and put the .htaccess file there . Referencing to centOS and Cpanel hosting for laravel.

                                      – Deepesh Thapa
                                      Apr 19 '18 at 21:23











                                    • What's the flaws with using this method?

                                      – Script47
                                      Oct 10 '18 at 23:40














                                    19












                                    19








                                    19







                                    Just create .htaccess file at root and add these lines to it



                                    <IfModule mod_rewrite.c>
                                    RewriteEngine On

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


                                    That's it!



                                    The above code works on the root public_html folder. Having said that your core laravel file should be inside the public_html folder, if your directory looks like public_html/laravelapp/public and if you put the above code inside laravelapp it won't work. Therefore you must copy all your core files into public_html and put the .htaccess file there .



                                    If you want to keep the code in a subdirectory then you can create a subdomain then this code will work for that also.






                                    share|improve this answer















                                    Just create .htaccess file at root and add these lines to it



                                    <IfModule mod_rewrite.c>
                                    RewriteEngine On

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


                                    That's it!



                                    The above code works on the root public_html folder. Having said that your core laravel file should be inside the public_html folder, if your directory looks like public_html/laravelapp/public and if you put the above code inside laravelapp it won't work. Therefore you must copy all your core files into public_html and put the .htaccess file there .



                                    If you want to keep the code in a subdirectory then you can create a subdomain then this code will work for that also.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jul 3 '18 at 6:20

























                                    answered Dec 12 '17 at 11:57









                                    Abhinav SaraswatAbhinav Saraswat

                                    37427




                                    37427













                                    • I answered below before reading your answer and this must be the accepted answer. No file changes: just a simple, clever rule.

                                      – Brigo
                                      Jan 27 '18 at 17:40











                                    • @Raham what is your current url?

                                      – Abhinav Saraswat
                                      Feb 5 '18 at 6:30






                                    • 2





                                      Just want to add a short description on top of this gentlemen's work. The above code works on the root public_html folder (I had issues as well). Having said that your core laravel file should be inside public_html folder , i made a mistake that my directory looked like public_html/laravelapp/public if you put the above code inside laravelapp it wont work . Therefore you must copy all your core files into public_html and put the .htaccess file there . Referencing to centOS and Cpanel hosting for laravel.

                                      – Deepesh Thapa
                                      Apr 19 '18 at 21:23











                                    • What's the flaws with using this method?

                                      – Script47
                                      Oct 10 '18 at 23:40



















                                    • I answered below before reading your answer and this must be the accepted answer. No file changes: just a simple, clever rule.

                                      – Brigo
                                      Jan 27 '18 at 17:40











                                    • @Raham what is your current url?

                                      – Abhinav Saraswat
                                      Feb 5 '18 at 6:30






                                    • 2





                                      Just want to add a short description on top of this gentlemen's work. The above code works on the root public_html folder (I had issues as well). Having said that your core laravel file should be inside public_html folder , i made a mistake that my directory looked like public_html/laravelapp/public if you put the above code inside laravelapp it wont work . Therefore you must copy all your core files into public_html and put the .htaccess file there . Referencing to centOS and Cpanel hosting for laravel.

                                      – Deepesh Thapa
                                      Apr 19 '18 at 21:23











                                    • What's the flaws with using this method?

                                      – Script47
                                      Oct 10 '18 at 23:40

















                                    I answered below before reading your answer and this must be the accepted answer. No file changes: just a simple, clever rule.

                                    – Brigo
                                    Jan 27 '18 at 17:40





                                    I answered below before reading your answer and this must be the accepted answer. No file changes: just a simple, clever rule.

                                    – Brigo
                                    Jan 27 '18 at 17:40













                                    @Raham what is your current url?

                                    – Abhinav Saraswat
                                    Feb 5 '18 at 6:30





                                    @Raham what is your current url?

                                    – Abhinav Saraswat
                                    Feb 5 '18 at 6:30




                                    2




                                    2





                                    Just want to add a short description on top of this gentlemen's work. The above code works on the root public_html folder (I had issues as well). Having said that your core laravel file should be inside public_html folder , i made a mistake that my directory looked like public_html/laravelapp/public if you put the above code inside laravelapp it wont work . Therefore you must copy all your core files into public_html and put the .htaccess file there . Referencing to centOS and Cpanel hosting for laravel.

                                    – Deepesh Thapa
                                    Apr 19 '18 at 21:23





                                    Just want to add a short description on top of this gentlemen's work. The above code works on the root public_html folder (I had issues as well). Having said that your core laravel file should be inside public_html folder , i made a mistake that my directory looked like public_html/laravelapp/public if you put the above code inside laravelapp it wont work . Therefore you must copy all your core files into public_html and put the .htaccess file there . Referencing to centOS and Cpanel hosting for laravel.

                                    – Deepesh Thapa
                                    Apr 19 '18 at 21:23













                                    What's the flaws with using this method?

                                    – Script47
                                    Oct 10 '18 at 23:40





                                    What's the flaws with using this method?

                                    – Script47
                                    Oct 10 '18 at 23:40











                                    14














                                    Even if the solution(s) mentioned in this thread works for you guys, I would request you not to do this. Here is the reason why.



                                    You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.



                                    The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.



                                    Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.



                                    If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory of public_html, do the same but create symlink from $LARAVEL_PATH/public to public_html/$PROJECT_SUBDIR.



                                    That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)






                                    share|improve this answer





















                                    • 2





                                      i accept your answer bcoz its secure for storage folder. Can you explain how to host the laravel app in shared hosting

                                      – Zaza
                                      Feb 19 '18 at 10:24








                                    • 1





                                      This really should be the accepted answer.

                                      – ceejayoz
                                      Oct 29 '18 at 15:03











                                    • @Zaza Sorry for late reply. To host laravel app in shared hosting, you can follow these steps dev.to/asapabedi/… Hope this helps.

                                      – Mittul At TechnoBrave
                                      Jan 16 at 4:43


















                                    14














                                    Even if the solution(s) mentioned in this thread works for you guys, I would request you not to do this. Here is the reason why.



                                    You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.



                                    The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.



                                    Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.



                                    If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory of public_html, do the same but create symlink from $LARAVEL_PATH/public to public_html/$PROJECT_SUBDIR.



                                    That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)






                                    share|improve this answer





















                                    • 2





                                      i accept your answer bcoz its secure for storage folder. Can you explain how to host the laravel app in shared hosting

                                      – Zaza
                                      Feb 19 '18 at 10:24








                                    • 1





                                      This really should be the accepted answer.

                                      – ceejayoz
                                      Oct 29 '18 at 15:03











                                    • @Zaza Sorry for late reply. To host laravel app in shared hosting, you can follow these steps dev.to/asapabedi/… Hope this helps.

                                      – Mittul At TechnoBrave
                                      Jan 16 at 4:43
















                                    14












                                    14








                                    14







                                    Even if the solution(s) mentioned in this thread works for you guys, I would request you not to do this. Here is the reason why.



                                    You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.



                                    The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.



                                    Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.



                                    If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory of public_html, do the same but create symlink from $LARAVEL_PATH/public to public_html/$PROJECT_SUBDIR.



                                    That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)






                                    share|improve this answer















                                    Even if the solution(s) mentioned in this thread works for you guys, I would request you not to do this. Here is the reason why.



                                    You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.



                                    The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.



                                    Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.



                                    If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory of public_html, do the same but create symlink from $LARAVEL_PATH/public to public_html/$PROJECT_SUBDIR.



                                    That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Oct 18 '18 at 13:10

























                                    answered Jan 5 '18 at 6:20









                                    Mittul At TechnoBraveMittul At TechnoBrave

                                    81811034




                                    81811034








                                    • 2





                                      i accept your answer bcoz its secure for storage folder. Can you explain how to host the laravel app in shared hosting

                                      – Zaza
                                      Feb 19 '18 at 10:24








                                    • 1





                                      This really should be the accepted answer.

                                      – ceejayoz
                                      Oct 29 '18 at 15:03











                                    • @Zaza Sorry for late reply. To host laravel app in shared hosting, you can follow these steps dev.to/asapabedi/… Hope this helps.

                                      – Mittul At TechnoBrave
                                      Jan 16 at 4:43
















                                    • 2





                                      i accept your answer bcoz its secure for storage folder. Can you explain how to host the laravel app in shared hosting

                                      – Zaza
                                      Feb 19 '18 at 10:24








                                    • 1





                                      This really should be the accepted answer.

                                      – ceejayoz
                                      Oct 29 '18 at 15:03











                                    • @Zaza Sorry for late reply. To host laravel app in shared hosting, you can follow these steps dev.to/asapabedi/… Hope this helps.

                                      – Mittul At TechnoBrave
                                      Jan 16 at 4:43










                                    2




                                    2





                                    i accept your answer bcoz its secure for storage folder. Can you explain how to host the laravel app in shared hosting

                                    – Zaza
                                    Feb 19 '18 at 10:24







                                    i accept your answer bcoz its secure for storage folder. Can you explain how to host the laravel app in shared hosting

                                    – Zaza
                                    Feb 19 '18 at 10:24






                                    1




                                    1





                                    This really should be the accepted answer.

                                    – ceejayoz
                                    Oct 29 '18 at 15:03





                                    This really should be the accepted answer.

                                    – ceejayoz
                                    Oct 29 '18 at 15:03













                                    @Zaza Sorry for late reply. To host laravel app in shared hosting, you can follow these steps dev.to/asapabedi/… Hope this helps.

                                    – Mittul At TechnoBrave
                                    Jan 16 at 4:43







                                    @Zaza Sorry for late reply. To host laravel app in shared hosting, you can follow these steps dev.to/asapabedi/… Hope this helps.

                                    – Mittul At TechnoBrave
                                    Jan 16 at 4:43













                                    12














                                    It's possible to remove public 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';


                                    And remove all cache and cookies.






                                    share|improve this answer


























                                    • Hi, I have tried your method, performed the above steps but it shows the following errors: Warning: require_once(D:Projectslaravel/public/index.php): failed to open stream: No such file or directory in D:Projectslaravelserver.php on line 21 Fatal error: require_once(): Failed opening required 'D:Projectslaravel/public/index.php' (include_path='.;C:xamppphpPEAR') in D:Projectslaravelserver.php on line 21

                                      – Ali Shahzad
                                      Mar 8 '15 at 7:26
















                                    12














                                    It's possible to remove public 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';


                                    And remove all cache and cookies.






                                    share|improve this answer


























                                    • Hi, I have tried your method, performed the above steps but it shows the following errors: Warning: require_once(D:Projectslaravel/public/index.php): failed to open stream: No such file or directory in D:Projectslaravelserver.php on line 21 Fatal error: require_once(): Failed opening required 'D:Projectslaravel/public/index.php' (include_path='.;C:xamppphpPEAR') in D:Projectslaravelserver.php on line 21

                                      – Ali Shahzad
                                      Mar 8 '15 at 7:26














                                    12












                                    12








                                    12







                                    It's possible to remove public 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';


                                    And remove all cache and cookies.






                                    share|improve this answer















                                    It's possible to remove public 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';


                                    And remove all cache and cookies.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Dec 28 '18 at 19:54









                                    Jignesh Joisar

                                    2,66511021




                                    2,66511021










                                    answered Feb 11 '15 at 8:17









                                    piyush patelpiyush patel

                                    1477




                                    1477













                                    • Hi, I have tried your method, performed the above steps but it shows the following errors: Warning: require_once(D:Projectslaravel/public/index.php): failed to open stream: No such file or directory in D:Projectslaravelserver.php on line 21 Fatal error: require_once(): Failed opening required 'D:Projectslaravel/public/index.php' (include_path='.;C:xamppphpPEAR') in D:Projectslaravelserver.php on line 21

                                      – Ali Shahzad
                                      Mar 8 '15 at 7:26



















                                    • Hi, I have tried your method, performed the above steps but it shows the following errors: Warning: require_once(D:Projectslaravel/public/index.php): failed to open stream: No such file or directory in D:Projectslaravelserver.php on line 21 Fatal error: require_once(): Failed opening required 'D:Projectslaravel/public/index.php' (include_path='.;C:xamppphpPEAR') in D:Projectslaravelserver.php on line 21

                                      – Ali Shahzad
                                      Mar 8 '15 at 7:26

















                                    Hi, I have tried your method, performed the above steps but it shows the following errors: Warning: require_once(D:Projectslaravel/public/index.php): failed to open stream: No such file or directory in D:Projectslaravelserver.php on line 21 Fatal error: require_once(): Failed opening required 'D:Projectslaravel/public/index.php' (include_path='.;C:xamppphpPEAR') in D:Projectslaravelserver.php on line 21

                                    – Ali Shahzad
                                    Mar 8 '15 at 7:26





                                    Hi, I have tried your method, performed the above steps but it shows the following errors: Warning: require_once(D:Projectslaravel/public/index.php): failed to open stream: No such file or directory in D:Projectslaravelserver.php on line 21 Fatal error: require_once(): Failed opening required 'D:Projectslaravel/public/index.php' (include_path='.;C:xamppphpPEAR') in D:Projectslaravelserver.php on line 21

                                    – Ali Shahzad
                                    Mar 8 '15 at 7:26











                                    11














                                    Let's say you placed all the other files and directories in a folder named 'locale'.



                                    enter image description here



                                    Just go to index.php and find these two lines:



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

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


                                    and change them to this:



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

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





                                    share|improve this answer






























                                      11














                                      Let's say you placed all the other files and directories in a folder named 'locale'.



                                      enter image description here



                                      Just go to index.php and find these two lines:



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

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


                                      and change them to this:



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

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





                                      share|improve this answer




























                                        11












                                        11








                                        11







                                        Let's say you placed all the other files and directories in a folder named 'locale'.



                                        enter image description here



                                        Just go to index.php and find these two lines:



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

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


                                        and change them to this:



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

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





                                        share|improve this answer















                                        Let's say you placed all the other files and directories in a folder named 'locale'.



                                        enter image description here



                                        Just go to index.php and find these two lines:



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

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


                                        and change them to this:



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

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






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Feb 19 '15 at 17:26

























                                        answered Feb 19 '15 at 15:39









                                        Angelo Joseph SalvadorAngelo Joseph Salvador

                                        312515




                                        312515























                                            8














                                            BEST Approach:
                                            I will not recommend removing public, instead on local computer create a virtual host point to public directory and on remote hosting change public to public_html and point your domain to this directory. Reason, your whole laravel code will be secure because its one level down to your public directory :)



                                            METHOD 1:



                                            I just rename server.php to index.php and it works



                                            METHOD 2:



                                            This work well for all laravel version...



                                            Here is my Directory Structure,



                                            /laravel/
                                            ... app
                                            ... bootstrap
                                            ... public
                                            ... etc


                                            Follow these easy steps




                                            1. move all files from public directory to root /laravel/

                                            2. now, no need of public directory, so optionally you can remove it now

                                            3. now open index.php and make following replacements



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




                                            to




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




                                            and




                                            $app = require_once DIR.'/../bootstrap/start.php';




                                            to




                                            $app = require_once DIR.'/bootstrap/start.php';





                                            1. now open bootstrap/paths.php and change public directory path:



                                            'public' => DIR.'/../public',




                                            to




                                            'public' => DIR.'/..',




                                            and that's it, now try http:// localhost/laravel/






                                            share|improve this answer


























                                            • Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" . Is there any suggestion ?

                                              – Kabir Hossain
                                              Jan 29 '17 at 5:45













                                            • Thanks wasim a, Method 2 is working for me

                                              – Faridul Khan
                                              Nov 25 '17 at 12:02











                                            • This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env

                                              – MasoodUrRehman
                                              Dec 23 '17 at 14:43
















                                            8














                                            BEST Approach:
                                            I will not recommend removing public, instead on local computer create a virtual host point to public directory and on remote hosting change public to public_html and point your domain to this directory. Reason, your whole laravel code will be secure because its one level down to your public directory :)



                                            METHOD 1:



                                            I just rename server.php to index.php and it works



                                            METHOD 2:



                                            This work well for all laravel version...



                                            Here is my Directory Structure,



                                            /laravel/
                                            ... app
                                            ... bootstrap
                                            ... public
                                            ... etc


                                            Follow these easy steps




                                            1. move all files from public directory to root /laravel/

                                            2. now, no need of public directory, so optionally you can remove it now

                                            3. now open index.php and make following replacements



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




                                            to




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




                                            and




                                            $app = require_once DIR.'/../bootstrap/start.php';




                                            to




                                            $app = require_once DIR.'/bootstrap/start.php';





                                            1. now open bootstrap/paths.php and change public directory path:



                                            'public' => DIR.'/../public',




                                            to




                                            'public' => DIR.'/..',




                                            and that's it, now try http:// localhost/laravel/






                                            share|improve this answer


























                                            • Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" . Is there any suggestion ?

                                              – Kabir Hossain
                                              Jan 29 '17 at 5:45













                                            • Thanks wasim a, Method 2 is working for me

                                              – Faridul Khan
                                              Nov 25 '17 at 12:02











                                            • This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env

                                              – MasoodUrRehman
                                              Dec 23 '17 at 14:43














                                            8












                                            8








                                            8







                                            BEST Approach:
                                            I will not recommend removing public, instead on local computer create a virtual host point to public directory and on remote hosting change public to public_html and point your domain to this directory. Reason, your whole laravel code will be secure because its one level down to your public directory :)



                                            METHOD 1:



                                            I just rename server.php to index.php and it works



                                            METHOD 2:



                                            This work well for all laravel version...



                                            Here is my Directory Structure,



                                            /laravel/
                                            ... app
                                            ... bootstrap
                                            ... public
                                            ... etc


                                            Follow these easy steps




                                            1. move all files from public directory to root /laravel/

                                            2. now, no need of public directory, so optionally you can remove it now

                                            3. now open index.php and make following replacements



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




                                            to




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




                                            and




                                            $app = require_once DIR.'/../bootstrap/start.php';




                                            to




                                            $app = require_once DIR.'/bootstrap/start.php';





                                            1. now open bootstrap/paths.php and change public directory path:



                                            'public' => DIR.'/../public',




                                            to




                                            'public' => DIR.'/..',




                                            and that's it, now try http:// localhost/laravel/






                                            share|improve this answer















                                            BEST Approach:
                                            I will not recommend removing public, instead on local computer create a virtual host point to public directory and on remote hosting change public to public_html and point your domain to this directory. Reason, your whole laravel code will be secure because its one level down to your public directory :)



                                            METHOD 1:



                                            I just rename server.php to index.php and it works



                                            METHOD 2:



                                            This work well for all laravel version...



                                            Here is my Directory Structure,



                                            /laravel/
                                            ... app
                                            ... bootstrap
                                            ... public
                                            ... etc


                                            Follow these easy steps




                                            1. move all files from public directory to root /laravel/

                                            2. now, no need of public directory, so optionally you can remove it now

                                            3. now open index.php and make following replacements



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




                                            to




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




                                            and




                                            $app = require_once DIR.'/../bootstrap/start.php';




                                            to




                                            $app = require_once DIR.'/bootstrap/start.php';





                                            1. now open bootstrap/paths.php and change public directory path:



                                            'public' => DIR.'/../public',




                                            to




                                            'public' => DIR.'/..',




                                            and that's it, now try http:// localhost/laravel/







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Dec 15 '18 at 5:52

























                                            answered Sep 14 '16 at 12:16









                                            Wasim A.Wasim A.

                                            4,6581968102




                                            4,6581968102













                                            • Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" . Is there any suggestion ?

                                              – Kabir Hossain
                                              Jan 29 '17 at 5:45













                                            • Thanks wasim a, Method 2 is working for me

                                              – Faridul Khan
                                              Nov 25 '17 at 12:02











                                            • This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env

                                              – MasoodUrRehman
                                              Dec 23 '17 at 14:43



















                                            • Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" . Is there any suggestion ?

                                              – Kabir Hossain
                                              Jan 29 '17 at 5:45













                                            • Thanks wasim a, Method 2 is working for me

                                              – Faridul Khan
                                              Nov 25 '17 at 12:02











                                            • This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env

                                              – MasoodUrRehman
                                              Dec 23 '17 at 14:43

















                                            Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" . Is there any suggestion ?

                                            – Kabir Hossain
                                            Jan 29 '17 at 5:45







                                            Its ok for everything. but artisan command is not working, just it show "Could not open input file: artisan" . Is there any suggestion ?

                                            – Kabir Hossain
                                            Jan 29 '17 at 5:45















                                            Thanks wasim a, Method 2 is working for me

                                            – Faridul Khan
                                            Nov 25 '17 at 12:02





                                            Thanks wasim a, Method 2 is working for me

                                            – Faridul Khan
                                            Nov 25 '17 at 12:02













                                            This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env

                                            – MasoodUrRehman
                                            Dec 23 '17 at 14:43





                                            This method worked, If you are OK to expose your database credentials to users. localhost/laravel/.env

                                            – MasoodUrRehman
                                            Dec 23 '17 at 14:43











                                            6














                                            I would like to add to @Humble Learner and note that the proper location to "fix" the url path for assets is /Illuminate/Routing/UrlGenerator.php/asset().



                                            Update the method to match:



                                            public function asset($path, $secure = null)
                                            {
                                            if ($this->isValidUrl($path)) return $path;
                                            $root = $this->getRootUrl($this->getScheme($secure));
                                            return $this->removeIndex($root).'/public/'.trim($path, '/');
                                            }


                                            This will fix scripts, styles and image paths. Anything for asset paths.






                                            share|improve this answer




























                                              6














                                              I would like to add to @Humble Learner and note that the proper location to "fix" the url path for assets is /Illuminate/Routing/UrlGenerator.php/asset().



                                              Update the method to match:



                                              public function asset($path, $secure = null)
                                              {
                                              if ($this->isValidUrl($path)) return $path;
                                              $root = $this->getRootUrl($this->getScheme($secure));
                                              return $this->removeIndex($root).'/public/'.trim($path, '/');
                                              }


                                              This will fix scripts, styles and image paths. Anything for asset paths.






                                              share|improve this answer


























                                                6












                                                6








                                                6







                                                I would like to add to @Humble Learner and note that the proper location to "fix" the url path for assets is /Illuminate/Routing/UrlGenerator.php/asset().



                                                Update the method to match:



                                                public function asset($path, $secure = null)
                                                {
                                                if ($this->isValidUrl($path)) return $path;
                                                $root = $this->getRootUrl($this->getScheme($secure));
                                                return $this->removeIndex($root).'/public/'.trim($path, '/');
                                                }


                                                This will fix scripts, styles and image paths. Anything for asset paths.






                                                share|improve this answer













                                                I would like to add to @Humble Learner and note that the proper location to "fix" the url path for assets is /Illuminate/Routing/UrlGenerator.php/asset().



                                                Update the method to match:



                                                public function asset($path, $secure = null)
                                                {
                                                if ($this->isValidUrl($path)) return $path;
                                                $root = $this->getRootUrl($this->getScheme($secure));
                                                return $this->removeIndex($root).'/public/'.trim($path, '/');
                                                }


                                                This will fix scripts, styles and image paths. Anything for asset paths.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 2 '15 at 3:10









                                                Sean PerkinsSean Perkins

                                                481310




                                                481310























                                                    4














                                                    There is always a reason to have a public folder in the Laravel setup, all public related stuffs should be present inside the public folder,




                                                    Don't Point your ip address/domain to the Laravel's root folder but point it to the public folder. It is unsafe pointing the server Ip to the root folder., because unless you write restrictions in .htaccess, one can easily access the other files.,




                                                    Just write rewrite condition in the .htaccess file and install rewrite module and enable the rewrite module, the problem which adds public in the route will get solved.






                                                    share|improve this answer



















                                                    • 1





                                                      You are correct .. Why we should break the things which framework is providing by default. We should try to understand the reason behind this before breaking this.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:13






                                                    • 1





                                                      I guess this answer should get more up-votes as it is suggesting users not to follow the steps which however are working as it will make security concerns by following those.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:40


















                                                    4














                                                    There is always a reason to have a public folder in the Laravel setup, all public related stuffs should be present inside the public folder,




                                                    Don't Point your ip address/domain to the Laravel's root folder but point it to the public folder. It is unsafe pointing the server Ip to the root folder., because unless you write restrictions in .htaccess, one can easily access the other files.,




                                                    Just write rewrite condition in the .htaccess file and install rewrite module and enable the rewrite module, the problem which adds public in the route will get solved.






                                                    share|improve this answer



















                                                    • 1





                                                      You are correct .. Why we should break the things which framework is providing by default. We should try to understand the reason behind this before breaking this.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:13






                                                    • 1





                                                      I guess this answer should get more up-votes as it is suggesting users not to follow the steps which however are working as it will make security concerns by following those.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:40
















                                                    4












                                                    4








                                                    4







                                                    There is always a reason to have a public folder in the Laravel setup, all public related stuffs should be present inside the public folder,




                                                    Don't Point your ip address/domain to the Laravel's root folder but point it to the public folder. It is unsafe pointing the server Ip to the root folder., because unless you write restrictions in .htaccess, one can easily access the other files.,




                                                    Just write rewrite condition in the .htaccess file and install rewrite module and enable the rewrite module, the problem which adds public in the route will get solved.






                                                    share|improve this answer













                                                    There is always a reason to have a public folder in the Laravel setup, all public related stuffs should be present inside the public folder,




                                                    Don't Point your ip address/domain to the Laravel's root folder but point it to the public folder. It is unsafe pointing the server Ip to the root folder., because unless you write restrictions in .htaccess, one can easily access the other files.,




                                                    Just write rewrite condition in the .htaccess file and install rewrite module and enable the rewrite module, the problem which adds public in the route will get solved.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Apr 19 '17 at 10:29









                                                    Reiah Paul SamReiah Paul Sam

                                                    429312




                                                    429312








                                                    • 1





                                                      You are correct .. Why we should break the things which framework is providing by default. We should try to understand the reason behind this before breaking this.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:13






                                                    • 1





                                                      I guess this answer should get more up-votes as it is suggesting users not to follow the steps which however are working as it will make security concerns by following those.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:40
















                                                    • 1





                                                      You are correct .. Why we should break the things which framework is providing by default. We should try to understand the reason behind this before breaking this.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:13






                                                    • 1





                                                      I guess this answer should get more up-votes as it is suggesting users not to follow the steps which however are working as it will make security concerns by following those.

                                                      – Mittul At TechnoBrave
                                                      Sep 27 '17 at 11:40










                                                    1




                                                    1





                                                    You are correct .. Why we should break the things which framework is providing by default. We should try to understand the reason behind this before breaking this.

                                                    – Mittul At TechnoBrave
                                                    Sep 27 '17 at 11:13





                                                    You are correct .. Why we should break the things which framework is providing by default. We should try to understand the reason behind this before breaking this.

                                                    – Mittul At TechnoBrave
                                                    Sep 27 '17 at 11:13




                                                    1




                                                    1





                                                    I guess this answer should get more up-votes as it is suggesting users not to follow the steps which however are working as it will make security concerns by following those.

                                                    – Mittul At TechnoBrave
                                                    Sep 27 '17 at 11:40







                                                    I guess this answer should get more up-votes as it is suggesting users not to follow the steps which however are working as it will make security concerns by following those.

                                                    – Mittul At TechnoBrave
                                                    Sep 27 '17 at 11:40













                                                    4














                                                    For XAMPP user to remove public from url without touching laravel default filesystem is to set a Virtual Host for your application to do this jsut follow these steps




                                                    1. Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.


                                                    2. Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.


                                                    3. Open the file named httpd-vhosts.conf with a text editor.


                                                    4. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.


                                                    5. At the very bottom of the file paste the following code:



                                                    <VirtualHost *>
                                                    ServerAdmin admin@localhost.com
                                                    DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
                                                    ServerName localhost
                                                    ServerAlias localhost
                                                    <Directory "C:/xampp/htdocs">
                                                    Options Indexes FollowSymLinks Includes ExecCGI
                                                    Order allow,deny
                                                    Allow from all
                                                    </Directory>
                                                    </VirtualHost>



                                                    1. Now you can copy and paste the code above below to add your Virtual Host directories. For example I’m working on a site called Eatery Engine so the following snippet will allow me to work with sub-domains on my local install:


                                                    <VirtualHost eateryengine.dev>
                                                    ServerAdmin admin@localhost.com
                                                    DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your htdocs folder
                                                    ServerName eateryengine.dev
                                                    ServerAlias eateryengine.dev
                                                    <Directory "C:/xampp/htdocs/eateryengine">
                                                    Order allow,deny
                                                    Allow from all
                                                    </Directory>
                                                    </VirtualHost>



                                                    1. Next head over to your Windows host file to edit your HOSTS. the file will be located at C:/Windows/System32/drivers/etc/hosts, where hosts is the file. Open it with notepad.

                                                    2. Look for #localhost name resolution is handled within DNS itself.


                                                    127.0.0.1 localhost



                                                    localhost name resolution is handled within DNS itself.



                                                    127.0.0.1       localhost
                                                    127.0.0.1 eateryengine.dev #change to match your Virtual Host.
                                                    127.0.0.1 demo.eateryengine.dev #manually add new sub-domains.



                                                    1. Restart Apache and test everything.


                                                    The original article can be found here






                                                    share|improve this answer






























                                                      4














                                                      For XAMPP user to remove public from url without touching laravel default filesystem is to set a Virtual Host for your application to do this jsut follow these steps




                                                      1. Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.


                                                      2. Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.


                                                      3. Open the file named httpd-vhosts.conf with a text editor.


                                                      4. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.


                                                      5. At the very bottom of the file paste the following code:



                                                      <VirtualHost *>
                                                      ServerAdmin admin@localhost.com
                                                      DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
                                                      ServerName localhost
                                                      ServerAlias localhost
                                                      <Directory "C:/xampp/htdocs">
                                                      Options Indexes FollowSymLinks Includes ExecCGI
                                                      Order allow,deny
                                                      Allow from all
                                                      </Directory>
                                                      </VirtualHost>



                                                      1. Now you can copy and paste the code above below to add your Virtual Host directories. For example I’m working on a site called Eatery Engine so the following snippet will allow me to work with sub-domains on my local install:


                                                      <VirtualHost eateryengine.dev>
                                                      ServerAdmin admin@localhost.com
                                                      DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your htdocs folder
                                                      ServerName eateryengine.dev
                                                      ServerAlias eateryengine.dev
                                                      <Directory "C:/xampp/htdocs/eateryengine">
                                                      Order allow,deny
                                                      Allow from all
                                                      </Directory>
                                                      </VirtualHost>



                                                      1. Next head over to your Windows host file to edit your HOSTS. the file will be located at C:/Windows/System32/drivers/etc/hosts, where hosts is the file. Open it with notepad.

                                                      2. Look for #localhost name resolution is handled within DNS itself.


                                                      127.0.0.1 localhost



                                                      localhost name resolution is handled within DNS itself.



                                                      127.0.0.1       localhost
                                                      127.0.0.1 eateryengine.dev #change to match your Virtual Host.
                                                      127.0.0.1 demo.eateryengine.dev #manually add new sub-domains.



                                                      1. Restart Apache and test everything.


                                                      The original article can be found here






                                                      share|improve this answer




























                                                        4












                                                        4








                                                        4







                                                        For XAMPP user to remove public from url without touching laravel default filesystem is to set a Virtual Host for your application to do this jsut follow these steps




                                                        1. Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.


                                                        2. Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.


                                                        3. Open the file named httpd-vhosts.conf with a text editor.


                                                        4. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.


                                                        5. At the very bottom of the file paste the following code:



                                                        <VirtualHost *>
                                                        ServerAdmin admin@localhost.com
                                                        DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
                                                        ServerName localhost
                                                        ServerAlias localhost
                                                        <Directory "C:/xampp/htdocs">
                                                        Options Indexes FollowSymLinks Includes ExecCGI
                                                        Order allow,deny
                                                        Allow from all
                                                        </Directory>
                                                        </VirtualHost>



                                                        1. Now you can copy and paste the code above below to add your Virtual Host directories. For example I’m working on a site called Eatery Engine so the following snippet will allow me to work with sub-domains on my local install:


                                                        <VirtualHost eateryengine.dev>
                                                        ServerAdmin admin@localhost.com
                                                        DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your htdocs folder
                                                        ServerName eateryengine.dev
                                                        ServerAlias eateryengine.dev
                                                        <Directory "C:/xampp/htdocs/eateryengine">
                                                        Order allow,deny
                                                        Allow from all
                                                        </Directory>
                                                        </VirtualHost>



                                                        1. Next head over to your Windows host file to edit your HOSTS. the file will be located at C:/Windows/System32/drivers/etc/hosts, where hosts is the file. Open it with notepad.

                                                        2. Look for #localhost name resolution is handled within DNS itself.


                                                        127.0.0.1 localhost



                                                        localhost name resolution is handled within DNS itself.



                                                        127.0.0.1       localhost
                                                        127.0.0.1 eateryengine.dev #change to match your Virtual Host.
                                                        127.0.0.1 demo.eateryengine.dev #manually add new sub-domains.



                                                        1. Restart Apache and test everything.


                                                        The original article can be found here






                                                        share|improve this answer















                                                        For XAMPP user to remove public from url without touching laravel default filesystem is to set a Virtual Host for your application to do this jsut follow these steps




                                                        1. Open the XAMPP control panel application and stop Apache. Be aware that late Windows machines might run it as a service, so check the box to the left of the Apache module.


                                                        2. Navigate to C:/xampp/apache/conf/extra or wherever your XAMPP files are located.


                                                        3. Open the file named httpd-vhosts.conf with a text editor.


                                                        4. Around line 19 find # NameVirtualHost *:80 and uncomment or remove the hash.


                                                        5. At the very bottom of the file paste the following code:



                                                        <VirtualHost *>
                                                        ServerAdmin admin@localhost.com
                                                        DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
                                                        ServerName localhost
                                                        ServerAlias localhost
                                                        <Directory "C:/xampp/htdocs">
                                                        Options Indexes FollowSymLinks Includes ExecCGI
                                                        Order allow,deny
                                                        Allow from all
                                                        </Directory>
                                                        </VirtualHost>



                                                        1. Now you can copy and paste the code above below to add your Virtual Host directories. For example I’m working on a site called Eatery Engine so the following snippet will allow me to work with sub-domains on my local install:


                                                        <VirtualHost eateryengine.dev>
                                                        ServerAdmin admin@localhost.com
                                                        DocumentRoot "C:/xampp/htdocs/eateryengine" # change this line with your htdocs folder
                                                        ServerName eateryengine.dev
                                                        ServerAlias eateryengine.dev
                                                        <Directory "C:/xampp/htdocs/eateryengine">
                                                        Order allow,deny
                                                        Allow from all
                                                        </Directory>
                                                        </VirtualHost>



                                                        1. Next head over to your Windows host file to edit your HOSTS. the file will be located at C:/Windows/System32/drivers/etc/hosts, where hosts is the file. Open it with notepad.

                                                        2. Look for #localhost name resolution is handled within DNS itself.


                                                        127.0.0.1 localhost



                                                        localhost name resolution is handled within DNS itself.



                                                        127.0.0.1       localhost
                                                        127.0.0.1 eateryengine.dev #change to match your Virtual Host.
                                                        127.0.0.1 demo.eateryengine.dev #manually add new sub-domains.



                                                        1. Restart Apache and test everything.


                                                        The original article can be found here







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Jan 27 '18 at 9:05









                                                        pirho

                                                        4,405101830




                                                        4,405101830










                                                        answered Jul 19 '16 at 16:47









                                                        sunny kashyapsunny kashyap

                                                        49311017




                                                        49311017























                                                            4














                                                            Here is the Best and shortest solution that works for me as of may, 2018
                                                            for Laravel 5.5



                                                            1- just cut your .htaccess file from the /public directory to the root directory and replace it content with the following code:



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

                                                            RewriteEngine On

                                                            RewriteCond %{REQUEST_FILENAME} !-d
                                                            RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                            RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                                                            RewriteCond %{REQUEST_FILENAME} !-d
                                                            RewriteCond %{REQUEST_FILENAME} !-f
                                                            RewriteRule ^ server.php [L]

                                                            RewriteCond %{REQUEST_FILENAME} !-d
                                                            RewriteCond %{REQUEST_FILENAME} !-f
                                                            RewriteCond %{REQUEST_URI} !^/public/
                                                            RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

                                                            </IfModule>


                                                            2- Just save the .htaccess file and that is all.



                                                            3- Rename your server.php file to index.php. that is all enjoy!






                                                            share|improve this answer






























                                                              4














                                                              Here is the Best and shortest solution that works for me as of may, 2018
                                                              for Laravel 5.5



                                                              1- just cut your .htaccess file from the /public directory to the root directory and replace it content with the following code:



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

                                                              RewriteEngine On

                                                              RewriteCond %{REQUEST_FILENAME} !-d
                                                              RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                              RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                                                              RewriteCond %{REQUEST_FILENAME} !-d
                                                              RewriteCond %{REQUEST_FILENAME} !-f
                                                              RewriteRule ^ server.php [L]

                                                              RewriteCond %{REQUEST_FILENAME} !-d
                                                              RewriteCond %{REQUEST_FILENAME} !-f
                                                              RewriteCond %{REQUEST_URI} !^/public/
                                                              RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

                                                              </IfModule>


                                                              2- Just save the .htaccess file and that is all.



                                                              3- Rename your server.php file to index.php. that is all enjoy!






                                                              share|improve this answer




























                                                                4












                                                                4








                                                                4







                                                                Here is the Best and shortest solution that works for me as of may, 2018
                                                                for Laravel 5.5



                                                                1- just cut your .htaccess file from the /public directory to the root directory and replace it content with the following code:



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

                                                                RewriteEngine On

                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                                RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                RewriteRule ^ server.php [L]

                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                RewriteCond %{REQUEST_URI} !^/public/
                                                                RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

                                                                </IfModule>


                                                                2- Just save the .htaccess file and that is all.



                                                                3- Rename your server.php file to index.php. that is all enjoy!






                                                                share|improve this answer















                                                                Here is the Best and shortest solution that works for me as of may, 2018
                                                                for Laravel 5.5



                                                                1- just cut your .htaccess file from the /public directory to the root directory and replace it content with the following code:



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

                                                                RewriteEngine On

                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                                RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$ [NC]
                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                RewriteRule ^ server.php [L]

                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                RewriteCond %{REQUEST_URI} !^/public/
                                                                RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]

                                                                </IfModule>


                                                                2- Just save the .htaccess file and that is all.



                                                                3- Rename your server.php file to index.php. that is all enjoy!







                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Dec 13 '18 at 16:09

























                                                                answered May 17 '18 at 9:46









                                                                tony protony pro

                                                                1189




                                                                1189























                                                                    2














                                                                    Firstly you can use this steps




                                                                    For Laravel 5:



                                                                    1. Rename server.php in your Laravel root folder to index.php



                                                                    2. Copy the .htaccess file from /public directory to your Laravel root folder.




                                                                    source: https://stackoverflow.com/a/28735930



                                                                    after you follow these steps then you need to change all css and script path, but this will be tiring.



                                                                    Solution Proposal :simply you can make minor change the helpers::asset function.



                                                                    For this:




                                                                    1. open vendorlaravelframeworksrcIlluminateFoundationhelpers.php


                                                                    2. goto line 130



                                                                    3. write "public/".$path instead of $path,



                                                                      function asset($path, $secure = null){
                                                                      return app('url')->asset("public/".$path, $secure);
                                                                      }







                                                                    share|improve this answer





















                                                                    • 1





                                                                      Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.

                                                                      – Janaka Dombawela
                                                                      Nov 9 '18 at 10:48













                                                                    • @JanakaDombawela i don't think that way because:

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:32











                                                                    • @JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain experience

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:39


















                                                                    2














                                                                    Firstly you can use this steps




                                                                    For Laravel 5:



                                                                    1. Rename server.php in your Laravel root folder to index.php



                                                                    2. Copy the .htaccess file from /public directory to your Laravel root folder.




                                                                    source: https://stackoverflow.com/a/28735930



                                                                    after you follow these steps then you need to change all css and script path, but this will be tiring.



                                                                    Solution Proposal :simply you can make minor change the helpers::asset function.



                                                                    For this:




                                                                    1. open vendorlaravelframeworksrcIlluminateFoundationhelpers.php


                                                                    2. goto line 130



                                                                    3. write "public/".$path instead of $path,



                                                                      function asset($path, $secure = null){
                                                                      return app('url')->asset("public/".$path, $secure);
                                                                      }







                                                                    share|improve this answer





















                                                                    • 1





                                                                      Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.

                                                                      – Janaka Dombawela
                                                                      Nov 9 '18 at 10:48













                                                                    • @JanakaDombawela i don't think that way because:

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:32











                                                                    • @JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain experience

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:39
















                                                                    2












                                                                    2








                                                                    2







                                                                    Firstly you can use this steps




                                                                    For Laravel 5:



                                                                    1. Rename server.php in your Laravel root folder to index.php



                                                                    2. Copy the .htaccess file from /public directory to your Laravel root folder.




                                                                    source: https://stackoverflow.com/a/28735930



                                                                    after you follow these steps then you need to change all css and script path, but this will be tiring.



                                                                    Solution Proposal :simply you can make minor change the helpers::asset function.



                                                                    For this:




                                                                    1. open vendorlaravelframeworksrcIlluminateFoundationhelpers.php


                                                                    2. goto line 130



                                                                    3. write "public/".$path instead of $path,



                                                                      function asset($path, $secure = null){
                                                                      return app('url')->asset("public/".$path, $secure);
                                                                      }







                                                                    share|improve this answer















                                                                    Firstly you can use this steps




                                                                    For Laravel 5:



                                                                    1. Rename server.php in your Laravel root folder to index.php



                                                                    2. Copy the .htaccess file from /public directory to your Laravel root folder.




                                                                    source: https://stackoverflow.com/a/28735930



                                                                    after you follow these steps then you need to change all css and script path, but this will be tiring.



                                                                    Solution Proposal :simply you can make minor change the helpers::asset function.



                                                                    For this:




                                                                    1. open vendorlaravelframeworksrcIlluminateFoundationhelpers.php


                                                                    2. goto line 130



                                                                    3. write "public/".$path instead of $path,



                                                                      function asset($path, $secure = null){
                                                                      return app('url')->asset("public/".$path, $secure);
                                                                      }








                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Aug 14 '18 at 21:39

























                                                                    answered Aug 14 '18 at 21:19









                                                                    Ferhat KOÇERFerhat KOÇER

                                                                    1,6841314




                                                                    1,6841314








                                                                    • 1





                                                                      Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.

                                                                      – Janaka Dombawela
                                                                      Nov 9 '18 at 10:48













                                                                    • @JanakaDombawela i don't think that way because:

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:32











                                                                    • @JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain experience

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:39
















                                                                    • 1





                                                                      Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.

                                                                      – Janaka Dombawela
                                                                      Nov 9 '18 at 10:48













                                                                    • @JanakaDombawela i don't think that way because:

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:32











                                                                    • @JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain experience

                                                                      – Ferhat KOÇER
                                                                      Dec 13 '18 at 19:39










                                                                    1




                                                                    1





                                                                    Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.

                                                                    – Janaka Dombawela
                                                                    Nov 9 '18 at 10:48







                                                                    Rule number 1: Never edit a core file. Even if it looks easy and nice now, you will pay later.

                                                                    – Janaka Dombawela
                                                                    Nov 9 '18 at 10:48















                                                                    @JanakaDombawela i don't think that way because:

                                                                    – Ferhat KOÇER
                                                                    Dec 13 '18 at 19:32





                                                                    @JanakaDombawela i don't think that way because:

                                                                    – Ferhat KOÇER
                                                                    Dec 13 '18 at 19:32













                                                                    @JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain experience

                                                                    – Ferhat KOÇER
                                                                    Dec 13 '18 at 19:39







                                                                    @JanakaDombawela I don't think that way because: Senerio 1: If developer a experienced : Open source code is for this job Senerio 2: If developer is a junior, developer must do edit to source code for gain experience

                                                                    – Ferhat KOÇER
                                                                    Dec 13 '18 at 19:39













                                                                    2














                                                                    Don't:



                                                                    You really should not rename server.php in your Laravel root folder to index.php
                                                                    and copy the .htaccess file from /public directory to your Laravel root folder!



                                                                    This way everyone can access some of your files (.env for example). You don't want that!





                                                                    Do:



                                                                    Instead, you should create a .htaccess file in your root like this:



                                                                    RewriteEngine On
                                                                    RewriteCond %{REQUEST_URI} !^/public/
                                                                    RewriteRule ^(.*)$ /public/$1 [L,QSA]


                                                                    That's it.






                                                                    share|improve this answer



















                                                                    • 1





                                                                      this works for me. thanks bro. you saved my day

                                                                      – Emtiaz Zahid
                                                                      Jan 5 at 9:46






                                                                    • 1





                                                                      It worked best with Lumen on Apache server.

                                                                      – Almas Dusal
                                                                      Jan 24 at 1:50
















                                                                    2














                                                                    Don't:



                                                                    You really should not rename server.php in your Laravel root folder to index.php
                                                                    and copy the .htaccess file from /public directory to your Laravel root folder!



                                                                    This way everyone can access some of your files (.env for example). You don't want that!





                                                                    Do:



                                                                    Instead, you should create a .htaccess file in your root like this:



                                                                    RewriteEngine On
                                                                    RewriteCond %{REQUEST_URI} !^/public/
                                                                    RewriteRule ^(.*)$ /public/$1 [L,QSA]


                                                                    That's it.






                                                                    share|improve this answer



















                                                                    • 1





                                                                      this works for me. thanks bro. you saved my day

                                                                      – Emtiaz Zahid
                                                                      Jan 5 at 9:46






                                                                    • 1





                                                                      It worked best with Lumen on Apache server.

                                                                      – Almas Dusal
                                                                      Jan 24 at 1:50














                                                                    2












                                                                    2








                                                                    2







                                                                    Don't:



                                                                    You really should not rename server.php in your Laravel root folder to index.php
                                                                    and copy the .htaccess file from /public directory to your Laravel root folder!



                                                                    This way everyone can access some of your files (.env for example). You don't want that!





                                                                    Do:



                                                                    Instead, you should create a .htaccess file in your root like this:



                                                                    RewriteEngine On
                                                                    RewriteCond %{REQUEST_URI} !^/public/
                                                                    RewriteRule ^(.*)$ /public/$1 [L,QSA]


                                                                    That's it.






                                                                    share|improve this answer













                                                                    Don't:



                                                                    You really should not rename server.php in your Laravel root folder to index.php
                                                                    and copy the .htaccess file from /public directory to your Laravel root folder!



                                                                    This way everyone can access some of your files (.env for example). You don't want that!





                                                                    Do:



                                                                    Instead, you should create a .htaccess file in your root like this:



                                                                    RewriteEngine On
                                                                    RewriteCond %{REQUEST_URI} !^/public/
                                                                    RewriteRule ^(.*)$ /public/$1 [L,QSA]


                                                                    That's it.







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Nov 28 '18 at 10:13









                                                                    Derk Jan SpeelmanDerk Jan Speelman

                                                                    2,4771924




                                                                    2,4771924








                                                                    • 1





                                                                      this works for me. thanks bro. you saved my day

                                                                      – Emtiaz Zahid
                                                                      Jan 5 at 9:46






                                                                    • 1





                                                                      It worked best with Lumen on Apache server.

                                                                      – Almas Dusal
                                                                      Jan 24 at 1:50














                                                                    • 1





                                                                      this works for me. thanks bro. you saved my day

                                                                      – Emtiaz Zahid
                                                                      Jan 5 at 9:46






                                                                    • 1





                                                                      It worked best with Lumen on Apache server.

                                                                      – Almas Dusal
                                                                      Jan 24 at 1:50








                                                                    1




                                                                    1





                                                                    this works for me. thanks bro. you saved my day

                                                                    – Emtiaz Zahid
                                                                    Jan 5 at 9:46





                                                                    this works for me. thanks bro. you saved my day

                                                                    – Emtiaz Zahid
                                                                    Jan 5 at 9:46




                                                                    1




                                                                    1





                                                                    It worked best with Lumen on Apache server.

                                                                    – Almas Dusal
                                                                    Jan 24 at 1:50





                                                                    It worked best with Lumen on Apache server.

                                                                    – Almas Dusal
                                                                    Jan 24 at 1:50











                                                                    1














                                                                    Another method that I use is to create a symbolic link (in Linux, don't know about Win) using the ln command in htdocs or www i.e. ln projectname/public project
                                                                    The site is thus accessible via localhost/project






                                                                    share|improve this answer




























                                                                      1














                                                                      Another method that I use is to create a symbolic link (in Linux, don't know about Win) using the ln command in htdocs or www i.e. ln projectname/public project
                                                                      The site is thus accessible via localhost/project






                                                                      share|improve this answer


























                                                                        1












                                                                        1








                                                                        1







                                                                        Another method that I use is to create a symbolic link (in Linux, don't know about Win) using the ln command in htdocs or www i.e. ln projectname/public project
                                                                        The site is thus accessible via localhost/project






                                                                        share|improve this answer













                                                                        Another method that I use is to create a symbolic link (in Linux, don't know about Win) using the ln command in htdocs or www i.e. ln projectname/public project
                                                                        The site is thus accessible via localhost/project







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Nov 15 '16 at 15:26









                                                                        Eli MakumbaEli Makumba

                                                                        411




                                                                        411























                                                                            1














                                                                            I have read some article before and it's working fine but really don't know is safe or not



                                                                                a. Create new folder local.
                                                                            b. Move all project into the local folder expect public folder.
                                                                            c. Move all the content of public folder to project root.
                                                                            d. Delete the blank public folder
                                                                            f. Edit the index file.


                                                                            Edit the index.php



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


                                                                            to



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





                                                                            share|improve this answer




























                                                                              1














                                                                              I have read some article before and it's working fine but really don't know is safe or not



                                                                                  a. Create new folder local.
                                                                              b. Move all project into the local folder expect public folder.
                                                                              c. Move all the content of public folder to project root.
                                                                              d. Delete the blank public folder
                                                                              f. Edit the index file.


                                                                              Edit the index.php



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


                                                                              to



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





                                                                              share|improve this answer


























                                                                                1












                                                                                1








                                                                                1







                                                                                I have read some article before and it's working fine but really don't know is safe or not



                                                                                    a. Create new folder local.
                                                                                b. Move all project into the local folder expect public folder.
                                                                                c. Move all the content of public folder to project root.
                                                                                d. Delete the blank public folder
                                                                                f. Edit the index file.


                                                                                Edit the index.php



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


                                                                                to



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





                                                                                share|improve this answer













                                                                                I have read some article before and it's working fine but really don't know is safe or not



                                                                                    a. Create new folder local.
                                                                                b. Move all project into the local folder expect public folder.
                                                                                c. Move all the content of public folder to project root.
                                                                                d. Delete the blank public folder
                                                                                f. Edit the index file.


                                                                                Edit the index.php



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


                                                                                to



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






                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Feb 10 '17 at 15:31









                                                                                Yousef AltafYousef Altaf

                                                                                1,63922541




                                                                                1,63922541























                                                                                    1














                                                                                    Even if i do not recommend putting Laravel on the root folder there are some cases when it could not be avoided;
                                                                                    for those cases the above methods do not work for assets so i made a quick fix changing the htaccess:
                                                                                    after copying server.php to index.php edit the .htaccess file like so:



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

                                                                                    RewriteEngine On

                                                                                    ### fix file rewrites on root path ###
                                                                                    #select file url
                                                                                    RewriteCond %{REQUEST_URI} ^(.*)$
                                                                                    #if file exists in /public/<filename>
                                                                                    RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
                                                                                    #redirect to /public/<filename>
                                                                                    RewriteRule ^(.*)$ public/$1 [L]
                                                                                    ###############

                                                                                    # Redirect Trailing Slashes If Not A Folder...
                                                                                    RewriteCond %{REQUEST_FILENAME} !-d
                                                                                    RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                                                    # Handle Front Controller...

                                                                                    #RewriteCond %{REQUEST_FILENAME} -d # comment this rules or the user will read non-public file and folders!
                                                                                    #RewriteCond %{REQUEST_FILENAME} -f #
                                                                                    RewriteRule ^ index.php [L]
                                                                                    </IfModule>


                                                                                    This was a quick fix i had to make so anyone is welcome to upgrade it.






                                                                                    share|improve this answer




























                                                                                      1














                                                                                      Even if i do not recommend putting Laravel on the root folder there are some cases when it could not be avoided;
                                                                                      for those cases the above methods do not work for assets so i made a quick fix changing the htaccess:
                                                                                      after copying server.php to index.php edit the .htaccess file like so:



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

                                                                                      RewriteEngine On

                                                                                      ### fix file rewrites on root path ###
                                                                                      #select file url
                                                                                      RewriteCond %{REQUEST_URI} ^(.*)$
                                                                                      #if file exists in /public/<filename>
                                                                                      RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
                                                                                      #redirect to /public/<filename>
                                                                                      RewriteRule ^(.*)$ public/$1 [L]
                                                                                      ###############

                                                                                      # Redirect Trailing Slashes If Not A Folder...
                                                                                      RewriteCond %{REQUEST_FILENAME} !-d
                                                                                      RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                                                      # Handle Front Controller...

                                                                                      #RewriteCond %{REQUEST_FILENAME} -d # comment this rules or the user will read non-public file and folders!
                                                                                      #RewriteCond %{REQUEST_FILENAME} -f #
                                                                                      RewriteRule ^ index.php [L]
                                                                                      </IfModule>


                                                                                      This was a quick fix i had to make so anyone is welcome to upgrade it.






                                                                                      share|improve this answer


























                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        Even if i do not recommend putting Laravel on the root folder there are some cases when it could not be avoided;
                                                                                        for those cases the above methods do not work for assets so i made a quick fix changing the htaccess:
                                                                                        after copying server.php to index.php edit the .htaccess file like so:



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

                                                                                        RewriteEngine On

                                                                                        ### fix file rewrites on root path ###
                                                                                        #select file url
                                                                                        RewriteCond %{REQUEST_URI} ^(.*)$
                                                                                        #if file exists in /public/<filename>
                                                                                        RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
                                                                                        #redirect to /public/<filename>
                                                                                        RewriteRule ^(.*)$ public/$1 [L]
                                                                                        ###############

                                                                                        # Redirect Trailing Slashes If Not A Folder...
                                                                                        RewriteCond %{REQUEST_FILENAME} !-d
                                                                                        RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                                                        # Handle Front Controller...

                                                                                        #RewriteCond %{REQUEST_FILENAME} -d # comment this rules or the user will read non-public file and folders!
                                                                                        #RewriteCond %{REQUEST_FILENAME} -f #
                                                                                        RewriteRule ^ index.php [L]
                                                                                        </IfModule>


                                                                                        This was a quick fix i had to make so anyone is welcome to upgrade it.






                                                                                        share|improve this answer













                                                                                        Even if i do not recommend putting Laravel on the root folder there are some cases when it could not be avoided;
                                                                                        for those cases the above methods do not work for assets so i made a quick fix changing the htaccess:
                                                                                        after copying server.php to index.php edit the .htaccess file like so:



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

                                                                                        RewriteEngine On

                                                                                        ### fix file rewrites on root path ###
                                                                                        #select file url
                                                                                        RewriteCond %{REQUEST_URI} ^(.*)$
                                                                                        #if file exists in /public/<filename>
                                                                                        RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
                                                                                        #redirect to /public/<filename>
                                                                                        RewriteRule ^(.*)$ public/$1 [L]
                                                                                        ###############

                                                                                        # Redirect Trailing Slashes If Not A Folder...
                                                                                        RewriteCond %{REQUEST_FILENAME} !-d
                                                                                        RewriteRule ^(.*)/$ /$1 [L,R=301]

                                                                                        # Handle Front Controller...

                                                                                        #RewriteCond %{REQUEST_FILENAME} -d # comment this rules or the user will read non-public file and folders!
                                                                                        #RewriteCond %{REQUEST_FILENAME} -f #
                                                                                        RewriteRule ^ index.php [L]
                                                                                        </IfModule>


                                                                                        This was a quick fix i had to make so anyone is welcome to upgrade it.







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Sep 13 '17 at 20:12









                                                                                        PlokkoPlokko

                                                                                        3171517




                                                                                        3171517























                                                                                            1














                                                                                            Laravel 5.5



                                                                                            After having installed Laravel for the first time, I faced the renowned "public folder problem" and I came up with this solution that, in my personal opinion, is "cleaner" then the others I found on the Web.





                                                                                            Achievements




                                                                                            • Don't have public word in the URI

                                                                                            • Protect the .env file against curious people


                                                                                            Everything can be done just editing the .htaccess using mod_rewrite and four simple rules.





                                                                                            Steps




                                                                                            1. Move the .htaccess file in public/.htaccess in the main root

                                                                                            2. Edit it as below


                                                                                            I commented everything, so it should be clear (I hope) also to those who have never used mod_rewrite (not that I'm an expert, all the opposite). Also, to understand the rules, it must be clear that, in Laravel, if Bill connects to https://example.com, https://example.com/index.php is loaded. This file just contains the command header("refresh: 5; https://example.com/public/"), which sends the request to https://example.com/public/index.php. This second index.php is responsible to load the controller and other stuff.



                                                                                            # IfModule prevents the server error if the app is moved in an environment which doesn’t support mod_rewrite
                                                                                            <IfModule mod_rewrite.c>
                                                                                            <IfModule mod_negotiation.c>
                                                                                            Options -MultiViews
                                                                                            </IfModule>

                                                                                            RewriteEngine On

                                                                                            # RULES ORIGINALLY IN public/.htaccess ---
                                                                                            # Redirect Trailing Slashes If Not A Folder...
                                                                                            RewriteCond %{REQUEST_FILENAME} !-d
                                                                                            RewriteCond %{REQUEST_URI} (.+)/$
                                                                                            RewriteRule ^ %1 [L,R=301]

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

                                                                                            # Handle Authorization Header
                                                                                            RewriteCond %{HTTP:Authorization} .
                                                                                            RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
                                                                                            # --- END

                                                                                            # PERSONAL RULES ---
                                                                                            # All the requests on port 80 are redirected on HTTPS
                                                                                            RewriteCond %{SERVER_PORT} ^80$
                                                                                            RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

                                                                                            # When .env file is requested, server redirects to 404
                                                                                            RewriteRule ^.env$ - [R=404,L,NC]

                                                                                            # If the REQUEST_URI is empty (means: http://example.com), it loads /public/index.php
                                                                                            # N.B.: REQUEST_URI is *never* actually empty, it contains a slash that must be set as match as below
                                                                                            # .* means: anything can go here at least 0 times (= accepts any sequence of characters, including an empty string)
                                                                                            RewriteCond %{REQUEST_URI} ^/$
                                                                                            RewriteRule ^(.*) /public/index.php [L]

                                                                                            # If the current request is asking for a REQUEST_FILENAME that:
                                                                                            # a) !== existent directory
                                                                                            # b) !== existent file
                                                                                            # => if URI !== css||js||images/whatever => server loads /public/index.php, which is responsible to load the app and the related controller
                                                                                            RewriteCond %{REQUEST_FILENAME} !-d
                                                                                            RewriteCond %{REQUEST_FILENAME} !-f
                                                                                            RewriteRule !^(css|js|images|media)/(.*)$ /public/index.php [L,NC]

                                                                                            # If the current request is asking for a REQUEST_FILENAME that:
                                                                                            # a) !== existent directory
                                                                                            # b) !== existent file
                                                                                            # => if URI == css||js||images[=$1]/whatever[=$2] => server loads the resource at public/$1/$2
                                                                                            # If R flag is added, the server not only loads the resource at public/$1/$2 but redirects to it
                                                                                            # e.g.: bamboo.jpg resides in example.com/public/media/bamboo.jpg
                                                                                            # Client asks for example.com/media/bamboo.jpg
                                                                                            # Without R flag: the URI remains example.com/media/bamboo.jpg and loads the image
                                                                                            # With R flag: the server redirects the client to example.com/public/media/bamboo.jpg and loads the image
                                                                                            RewriteCond %{REQUEST_FILENAME} !-d
                                                                                            RewriteCond %{REQUEST_FILENAME} !-f
                                                                                            RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]
                                                                                            # --- END

                                                                                            </IfModule>


                                                                                            The following rule (originally in public/.htaccess) can be deleted. The same rule, in fact, is explicited in a more detailed way in the last two rules.



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




                                                                                            EDIT: I missed Abhinav Saraswat's solution and his answer should be the accepted one. Just one, simple and clear rule that redirects all the traffic to the public folder without modifying any file.






                                                                                            share|improve this answer






























                                                                                              1














                                                                                              Laravel 5.5



                                                                                              After having installed Laravel for the first time, I faced the renowned "public folder problem" and I came up with this solution that, in my personal opinion, is "cleaner" then the others I found on the Web.





                                                                                              Achievements




                                                                                              • Don't have public word in the URI

                                                                                              • Protect the .env file against curious people


                                                                                              Everything can be done just editing the .htaccess using mod_rewrite and four simple rules.





                                                                                              Steps




                                                                                              1. Move the .htaccess file in public/.htaccess in the main root

                                                                                              2. Edit it as below


                                                                                              I commented everything, so it should be clear (I hope) also to those who have never used mod_rewrite (not that I'm an expert, all the opposite). Also, to understand the rules, it must be clear that, in Laravel, if Bill connects to https://example.com, https://example.com/index.php is loaded. This file just contains the command header("refresh: 5; https://example.com/public/"), which sends the request to https://example.com/public/index.php. This second index.php is responsible to load the controller and other stuff.



                                                                                              # IfModule prevents the server error if the app is moved in an environment which doesn’t support mod_rewrite
                                                                                              <IfModule mod_rewrite.c>
                                                                                              <IfModule mod_negotiation.c>
                                                                                              Options -MultiViews
                                                                                              </IfModule>

                                                                                              RewriteEngine On

                                                                                              # RULES ORIGINALLY IN public/.htaccess ---
                                                                                              # Redirect Trailing Slashes If Not A Folder...
                                                                                              RewriteCond %{REQUEST_FILENAME} !-d
                                                                                              RewriteCond %{REQUEST_URI} (.+)/$
                                                                                              RewriteRule ^ %1 [L,R=301]

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

                                                                                              # Handle Authorization Header
                                                                                              RewriteCond %{HTTP:Authorization} .
                                                                                              RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
                                                                                              # --- END

                                                                                              # PERSONAL RULES ---
                                                                                              # All the requests on port 80 are redirected on HTTPS
                                                                                              RewriteCond %{SERVER_PORT} ^80$
                                                                                              RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

                                                                                              # When .env file is requested, server redirects to 404
                                                                                              RewriteRule ^.env$ - [R=404,L,NC]

                                                                                              # If the REQUEST_URI is empty (means: http://example.com), it loads /public/index.php
                                                                                              # N.B.: REQUEST_URI is *never* actually empty, it contains a slash that must be set as match as below
                                                                                              # .* means: anything can go here at least 0 times (= accepts any sequence of characters, including an empty string)
                                                                                              RewriteCond %{REQUEST_URI} ^/$
                                                                                              RewriteRule ^(.*) /public/index.php [L]

                                                                                              # If the current request is asking for a REQUEST_FILENAME that:
                                                                                              # a) !== existent directory
                                                                                              # b) !== existent file
                                                                                              # => if URI !== css||js||images/whatever => server loads /public/index.php, which is responsible to load the app and the related controller
                                                                                              RewriteCond %{REQUEST_FILENAME} !-d
                                                                                              RewriteCond %{REQUEST_FILENAME} !-f
                                                                                              RewriteRule !^(css|js|images|media)/(.*)$ /public/index.php [L,NC]

                                                                                              # If the current request is asking for a REQUEST_FILENAME that:
                                                                                              # a) !== existent directory
                                                                                              # b) !== existent file
                                                                                              # => if URI == css||js||images[=$1]/whatever[=$2] => server loads the resource at public/$1/$2
                                                                                              # If R flag is added, the server not only loads the resource at public/$1/$2 but redirects to it
                                                                                              # e.g.: bamboo.jpg resides in example.com/public/media/bamboo.jpg
                                                                                              # Client asks for example.com/media/bamboo.jpg
                                                                                              # Without R flag: the URI remains example.com/media/bamboo.jpg and loads the image
                                                                                              # With R flag: the server redirects the client to example.com/public/media/bamboo.jpg and loads the image
                                                                                              RewriteCond %{REQUEST_FILENAME} !-d
                                                                                              RewriteCond %{REQUEST_FILENAME} !-f
                                                                                              RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]
                                                                                              # --- END

                                                                                              </IfModule>


                                                                                              The following rule (originally in public/.htaccess) can be deleted. The same rule, in fact, is explicited in a more detailed way in the last two rules.



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




                                                                                              EDIT: I missed Abhinav Saraswat's solution and his answer should be the accepted one. Just one, simple and clear rule that redirects all the traffic to the public folder without modifying any file.






                                                                                              share|improve this answer




























                                                                                                1












                                                                                                1








                                                                                                1







                                                                                                Laravel 5.5



                                                                                                After having installed Laravel for the first time, I faced the renowned "public folder problem" and I came up with this solution that, in my personal opinion, is "cleaner" then the others I found on the Web.





                                                                                                Achievements




                                                                                                • Don't have public word in the URI

                                                                                                • Protect the .env file against curious people


                                                                                                Everything can be done just editing the .htaccess using mod_rewrite and four simple rules.





                                                                                                Steps




                                                                                                1. Move the .htaccess file in public/.htaccess in the main root

                                                                                                2. Edit it as below


                                                                                                I commented everything, so it should be clear (I hope) also to those who have never used mod_rewrite (not that I'm an expert, all the opposite). Also, to understand the rules, it must be clear that, in Laravel, if Bill connects to https://example.com, https://example.com/index.php is loaded. This file just contains the command header("refresh: 5; https://example.com/public/"), which sends the request to https://example.com/public/index.php. This second index.php is responsible to load the controller and other stuff.



                                                                                                # IfModule prevents the server error if the app is moved in an environment which doesn’t support mod_rewrite
                                                                                                <IfModule mod_rewrite.c>
                                                                                                <IfModule mod_negotiation.c>
                                                                                                Options -MultiViews
                                                                                                </IfModule>

                                                                                                RewriteEngine On

                                                                                                # RULES ORIGINALLY IN public/.htaccess ---
                                                                                                # Redirect Trailing Slashes If Not A Folder...
                                                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                                                RewriteCond %{REQUEST_URI} (.+)/$
                                                                                                RewriteRule ^ %1 [L,R=301]

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

                                                                                                # Handle Authorization Header
                                                                                                RewriteCond %{HTTP:Authorization} .
                                                                                                RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
                                                                                                # --- END

                                                                                                # PERSONAL RULES ---
                                                                                                # All the requests on port 80 are redirected on HTTPS
                                                                                                RewriteCond %{SERVER_PORT} ^80$
                                                                                                RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

                                                                                                # When .env file is requested, server redirects to 404
                                                                                                RewriteRule ^.env$ - [R=404,L,NC]

                                                                                                # If the REQUEST_URI is empty (means: http://example.com), it loads /public/index.php
                                                                                                # N.B.: REQUEST_URI is *never* actually empty, it contains a slash that must be set as match as below
                                                                                                # .* means: anything can go here at least 0 times (= accepts any sequence of characters, including an empty string)
                                                                                                RewriteCond %{REQUEST_URI} ^/$
                                                                                                RewriteRule ^(.*) /public/index.php [L]

                                                                                                # If the current request is asking for a REQUEST_FILENAME that:
                                                                                                # a) !== existent directory
                                                                                                # b) !== existent file
                                                                                                # => if URI !== css||js||images/whatever => server loads /public/index.php, which is responsible to load the app and the related controller
                                                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                                                RewriteRule !^(css|js|images|media)/(.*)$ /public/index.php [L,NC]

                                                                                                # If the current request is asking for a REQUEST_FILENAME that:
                                                                                                # a) !== existent directory
                                                                                                # b) !== existent file
                                                                                                # => if URI == css||js||images[=$1]/whatever[=$2] => server loads the resource at public/$1/$2
                                                                                                # If R flag is added, the server not only loads the resource at public/$1/$2 but redirects to it
                                                                                                # e.g.: bamboo.jpg resides in example.com/public/media/bamboo.jpg
                                                                                                # Client asks for example.com/media/bamboo.jpg
                                                                                                # Without R flag: the URI remains example.com/media/bamboo.jpg and loads the image
                                                                                                # With R flag: the server redirects the client to example.com/public/media/bamboo.jpg and loads the image
                                                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                                                RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]
                                                                                                # --- END

                                                                                                </IfModule>


                                                                                                The following rule (originally in public/.htaccess) can be deleted. The same rule, in fact, is explicited in a more detailed way in the last two rules.



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




                                                                                                EDIT: I missed Abhinav Saraswat's solution and his answer should be the accepted one. Just one, simple and clear rule that redirects all the traffic to the public folder without modifying any file.






                                                                                                share|improve this answer















                                                                                                Laravel 5.5



                                                                                                After having installed Laravel for the first time, I faced the renowned "public folder problem" and I came up with this solution that, in my personal opinion, is "cleaner" then the others I found on the Web.





                                                                                                Achievements




                                                                                                • Don't have public word in the URI

                                                                                                • Protect the .env file against curious people


                                                                                                Everything can be done just editing the .htaccess using mod_rewrite and four simple rules.





                                                                                                Steps




                                                                                                1. Move the .htaccess file in public/.htaccess in the main root

                                                                                                2. Edit it as below


                                                                                                I commented everything, so it should be clear (I hope) also to those who have never used mod_rewrite (not that I'm an expert, all the opposite). Also, to understand the rules, it must be clear that, in Laravel, if Bill connects to https://example.com, https://example.com/index.php is loaded. This file just contains the command header("refresh: 5; https://example.com/public/"), which sends the request to https://example.com/public/index.php. This second index.php is responsible to load the controller and other stuff.



                                                                                                # IfModule prevents the server error if the app is moved in an environment which doesn’t support mod_rewrite
                                                                                                <IfModule mod_rewrite.c>
                                                                                                <IfModule mod_negotiation.c>
                                                                                                Options -MultiViews
                                                                                                </IfModule>

                                                                                                RewriteEngine On

                                                                                                # RULES ORIGINALLY IN public/.htaccess ---
                                                                                                # Redirect Trailing Slashes If Not A Folder...
                                                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                                                RewriteCond %{REQUEST_URI} (.+)/$
                                                                                                RewriteRule ^ %1 [L,R=301]

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

                                                                                                # Handle Authorization Header
                                                                                                RewriteCond %{HTTP:Authorization} .
                                                                                                RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
                                                                                                # --- END

                                                                                                # PERSONAL RULES ---
                                                                                                # All the requests on port 80 are redirected on HTTPS
                                                                                                RewriteCond %{SERVER_PORT} ^80$
                                                                                                RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

                                                                                                # When .env file is requested, server redirects to 404
                                                                                                RewriteRule ^.env$ - [R=404,L,NC]

                                                                                                # If the REQUEST_URI is empty (means: http://example.com), it loads /public/index.php
                                                                                                # N.B.: REQUEST_URI is *never* actually empty, it contains a slash that must be set as match as below
                                                                                                # .* means: anything can go here at least 0 times (= accepts any sequence of characters, including an empty string)
                                                                                                RewriteCond %{REQUEST_URI} ^/$
                                                                                                RewriteRule ^(.*) /public/index.php [L]

                                                                                                # If the current request is asking for a REQUEST_FILENAME that:
                                                                                                # a) !== existent directory
                                                                                                # b) !== existent file
                                                                                                # => if URI !== css||js||images/whatever => server loads /public/index.php, which is responsible to load the app and the related controller
                                                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                                                RewriteRule !^(css|js|images|media)/(.*)$ /public/index.php [L,NC]

                                                                                                # If the current request is asking for a REQUEST_FILENAME that:
                                                                                                # a) !== existent directory
                                                                                                # b) !== existent file
                                                                                                # => if URI == css||js||images[=$1]/whatever[=$2] => server loads the resource at public/$1/$2
                                                                                                # If R flag is added, the server not only loads the resource at public/$1/$2 but redirects to it
                                                                                                # e.g.: bamboo.jpg resides in example.com/public/media/bamboo.jpg
                                                                                                # Client asks for example.com/media/bamboo.jpg
                                                                                                # Without R flag: the URI remains example.com/media/bamboo.jpg and loads the image
                                                                                                # With R flag: the server redirects the client to example.com/public/media/bamboo.jpg and loads the image
                                                                                                RewriteCond %{REQUEST_FILENAME} !-d
                                                                                                RewriteCond %{REQUEST_FILENAME} !-f
                                                                                                RewriteRule ^(css|js|images|media)/(.*)$ /public/$1/$2 [L,NC]
                                                                                                # --- END

                                                                                                </IfModule>


                                                                                                The following rule (originally in public/.htaccess) can be deleted. The same rule, in fact, is explicited in a more detailed way in the last two rules.



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




                                                                                                EDIT: I missed Abhinav Saraswat's solution and his answer should be the accepted one. Just one, simple and clear rule that redirects all the traffic to the public folder without modifying any file.







                                                                                                share|improve this answer














                                                                                                share|improve this answer



                                                                                                share|improve this answer








                                                                                                edited Jan 27 '18 at 22:13

























                                                                                                answered Jan 27 '18 at 16:36









                                                                                                BrigoBrigo

                                                                                                574420




                                                                                                574420























                                                                                                    0














                                                                                                     You can follow only 2 step


                                                                                                    1- cut .htaccess from public folder and paste to root(mainFolder)
                                                                                                    2- Rename server.php file to index.php AT your root dir. (mainFolder)





                                                                                                    share|improve this answer




























                                                                                                      0














                                                                                                       You can follow only 2 step


                                                                                                      1- cut .htaccess from public folder and paste to root(mainFolder)
                                                                                                      2- Rename server.php file to index.php AT your root dir. (mainFolder)





                                                                                                      share|improve this answer


























                                                                                                        0












                                                                                                        0








                                                                                                        0







                                                                                                         You can follow only 2 step


                                                                                                        1- cut .htaccess from public folder and paste to root(mainFolder)
                                                                                                        2- Rename server.php file to index.php AT your root dir. (mainFolder)





                                                                                                        share|improve this answer













                                                                                                         You can follow only 2 step


                                                                                                        1- cut .htaccess from public folder and paste to root(mainFolder)
                                                                                                        2- Rename server.php file to index.php AT your root dir. (mainFolder)






                                                                                                        share|improve this answer












                                                                                                        share|improve this answer



                                                                                                        share|improve this answer










                                                                                                        answered Nov 10 '17 at 13:41









                                                                                                        Yagnesh bhalalaYagnesh bhalala

                                                                                                        400412




                                                                                                        400412























                                                                                                            0














                                                                                                            step 1:
                                                                                                            server.php file in root directory rename as index.php



                                                                                                            step 2:



                                                                                                            copy .htaccess file from public directory to root direct






                                                                                                            share|improve this answer


























                                                                                                            • server.php is not in the public folder. It is already in the root you just have to rename it.

                                                                                                              – Muhammad Wajahat Anwar
                                                                                                              Mar 2 '18 at 18:55











                                                                                                            • @MuhammadWajahatAnwar ya you right . i correct this

                                                                                                              – Ravindra Bhanderi
                                                                                                              Mar 3 '18 at 18:18
















                                                                                                            0














                                                                                                            step 1:
                                                                                                            server.php file in root directory rename as index.php



                                                                                                            step 2:



                                                                                                            copy .htaccess file from public directory to root direct






                                                                                                            share|improve this answer


























                                                                                                            • server.php is not in the public folder. It is already in the root you just have to rename it.

                                                                                                              – Muhammad Wajahat Anwar
                                                                                                              Mar 2 '18 at 18:55











                                                                                                            • @MuhammadWajahatAnwar ya you right . i correct this

                                                                                                              – Ravindra Bhanderi
                                                                                                              Mar 3 '18 at 18:18














                                                                                                            0












                                                                                                            0








                                                                                                            0







                                                                                                            step 1:
                                                                                                            server.php file in root directory rename as index.php



                                                                                                            step 2:



                                                                                                            copy .htaccess file from public directory to root direct






                                                                                                            share|improve this answer















                                                                                                            step 1:
                                                                                                            server.php file in root directory rename as index.php



                                                                                                            step 2:



                                                                                                            copy .htaccess file from public directory to root direct







                                                                                                            share|improve this answer














                                                                                                            share|improve this answer



                                                                                                            share|improve this answer








                                                                                                            edited Mar 3 '18 at 18:17

























                                                                                                            answered Mar 2 '18 at 5:07









                                                                                                            Ravindra BhanderiRavindra Bhanderi

                                                                                                            548218




                                                                                                            548218













                                                                                                            • server.php is not in the public folder. It is already in the root you just have to rename it.

                                                                                                              – Muhammad Wajahat Anwar
                                                                                                              Mar 2 '18 at 18:55











                                                                                                            • @MuhammadWajahatAnwar ya you right . i correct this

                                                                                                              – Ravindra Bhanderi
                                                                                                              Mar 3 '18 at 18:18



















                                                                                                            • server.php is not in the public folder. It is already in the root you just have to rename it.

                                                                                                              – Muhammad Wajahat Anwar
                                                                                                              Mar 2 '18 at 18:55











                                                                                                            • @MuhammadWajahatAnwar ya you right . i correct this

                                                                                                              – Ravindra Bhanderi
                                                                                                              Mar 3 '18 at 18:18

















                                                                                                            server.php is not in the public folder. It is already in the root you just have to rename it.

                                                                                                            – Muhammad Wajahat Anwar
                                                                                                            Mar 2 '18 at 18:55





                                                                                                            server.php is not in the public folder. It is already in the root you just have to rename it.

                                                                                                            – Muhammad Wajahat Anwar
                                                                                                            Mar 2 '18 at 18:55













                                                                                                            @MuhammadWajahatAnwar ya you right . i correct this

                                                                                                            – Ravindra Bhanderi
                                                                                                            Mar 3 '18 at 18:18





                                                                                                            @MuhammadWajahatAnwar ya you right . i correct this

                                                                                                            – Ravindra Bhanderi
                                                                                                            Mar 3 '18 at 18:18











                                                                                                            0














                                                                                                            You can remove public keyword from url using various methods.



                                                                                                            1) If you are using dedicated hosting and you have root access then You can remove public keyword from url using Virtual Host. You should give DocumentRoot path with public. So this will start index from public directory and remove it from url.



                                                                                                            <VirtualHost *:80>
                                                                                                            ServerAdmin info@example.com
                                                                                                            ServerName example.com
                                                                                                            ServerAlias www.example.com
                                                                                                            DocumentRoot /var/www/html/{yoursourcedirectory}/public

                                                                                                            ErrorLog ${APACHE_LOG_DIR}/error.log
                                                                                                            CustomLog ${APACHE_LOG_DIR}/access.log combined
                                                                                                            </VirtualHost>


                                                                                                            2) If you dont have root access of your hosting then you should genarate a new .htaccess file in your root directory and put the code as below



                                                                                                            <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>


                                                                                                            You can get more reference here.






                                                                                                            share|improve this answer




























                                                                                                              0














                                                                                                              You can remove public keyword from url using various methods.



                                                                                                              1) If you are using dedicated hosting and you have root access then You can remove public keyword from url using Virtual Host. You should give DocumentRoot path with public. So this will start index from public directory and remove it from url.



                                                                                                              <VirtualHost *:80>
                                                                                                              ServerAdmin info@example.com
                                                                                                              ServerName example.com
                                                                                                              ServerAlias www.example.com
                                                                                                              DocumentRoot /var/www/html/{yoursourcedirectory}/public

                                                                                                              ErrorLog ${APACHE_LOG_DIR}/error.log
                                                                                                              CustomLog ${APACHE_LOG_DIR}/access.log combined
                                                                                                              </VirtualHost>


                                                                                                              2) If you dont have root access of your hosting then you should genarate a new .htaccess file in your root directory and put the code as below



                                                                                                              <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>


                                                                                                              You can get more reference here.






                                                                                                              share|improve this answer


























                                                                                                                0












                                                                                                                0








                                                                                                                0







                                                                                                                You can remove public keyword from url using various methods.



                                                                                                                1) If you are using dedicated hosting and you have root access then You can remove public keyword from url using Virtual Host. You should give DocumentRoot path with public. So this will start index from public directory and remove it from url.



                                                                                                                <VirtualHost *:80>
                                                                                                                ServerAdmin info@example.com
                                                                                                                ServerName example.com
                                                                                                                ServerAlias www.example.com
                                                                                                                DocumentRoot /var/www/html/{yoursourcedirectory}/public

                                                                                                                ErrorLog ${APACHE_LOG_DIR}/error.log
                                                                                                                CustomLog ${APACHE_LOG_DIR}/access.log combined
                                                                                                                </VirtualHost>


                                                                                                                2) If you dont have root access of your hosting then you should genarate a new .htaccess file in your root directory and put the code as below



                                                                                                                <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>


                                                                                                                You can get more reference here.






                                                                                                                share|improve this answer













                                                                                                                You can remove public keyword from url using various methods.



                                                                                                                1) If you are using dedicated hosting and you have root access then You can remove public keyword from url using Virtual Host. You should give DocumentRoot path with public. So this will start index from public directory and remove it from url.



                                                                                                                <VirtualHost *:80>
                                                                                                                ServerAdmin info@example.com
                                                                                                                ServerName example.com
                                                                                                                ServerAlias www.example.com
                                                                                                                DocumentRoot /var/www/html/{yoursourcedirectory}/public

                                                                                                                ErrorLog ${APACHE_LOG_DIR}/error.log
                                                                                                                CustomLog ${APACHE_LOG_DIR}/access.log combined
                                                                                                                </VirtualHost>


                                                                                                                2) If you dont have root access of your hosting then you should genarate a new .htaccess file in your root directory and put the code as below



                                                                                                                <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>


                                                                                                                You can get more reference here.







                                                                                                                share|improve this answer












                                                                                                                share|improve this answer



                                                                                                                share|improve this answer










                                                                                                                answered Dec 27 '18 at 6:49









                                                                                                                Vinod JoshiVinod Joshi

                                                                                                                1016




                                                                                                                1016























                                                                                                                    0














                                                                                                                    I found the most working solution for this problem. Just edit your .htaccess in root folder and write the following code. Nothing else required



                                                                                                                      RewriteEngine on
                                                                                                                    RewriteCond %{REQUEST_URI} !^public
                                                                                                                    RewriteRule ^(.*)$ public/$1 [L]

                                                                                                                    <IfModule php7_module>
                                                                                                                    php_flag display_errors Off
                                                                                                                    php_value max_execution_time 30
                                                                                                                    php_value max_input_time 60
                                                                                                                    php_value max_input_vars 1000
                                                                                                                    php_value memory_limit -1
                                                                                                                    php_value post_max_size 8M
                                                                                                                    php_value session.gc_maxlifetime 1440
                                                                                                                    php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
                                                                                                                    php_value upload_max_filesize 2M
                                                                                                                    php_flag zlib.output_compression Off
                                                                                                                    </IfModule>





                                                                                                                    share|improve this answer




























                                                                                                                      0














                                                                                                                      I found the most working solution for this problem. Just edit your .htaccess in root folder and write the following code. Nothing else required



                                                                                                                        RewriteEngine on
                                                                                                                      RewriteCond %{REQUEST_URI} !^public
                                                                                                                      RewriteRule ^(.*)$ public/$1 [L]

                                                                                                                      <IfModule php7_module>
                                                                                                                      php_flag display_errors Off
                                                                                                                      php_value max_execution_time 30
                                                                                                                      php_value max_input_time 60
                                                                                                                      php_value max_input_vars 1000
                                                                                                                      php_value memory_limit -1
                                                                                                                      php_value post_max_size 8M
                                                                                                                      php_value session.gc_maxlifetime 1440
                                                                                                                      php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
                                                                                                                      php_value upload_max_filesize 2M
                                                                                                                      php_flag zlib.output_compression Off
                                                                                                                      </IfModule>





                                                                                                                      share|improve this answer


























                                                                                                                        0












                                                                                                                        0








                                                                                                                        0







                                                                                                                        I found the most working solution for this problem. Just edit your .htaccess in root folder and write the following code. Nothing else required



                                                                                                                          RewriteEngine on
                                                                                                                        RewriteCond %{REQUEST_URI} !^public
                                                                                                                        RewriteRule ^(.*)$ public/$1 [L]

                                                                                                                        <IfModule php7_module>
                                                                                                                        php_flag display_errors Off
                                                                                                                        php_value max_execution_time 30
                                                                                                                        php_value max_input_time 60
                                                                                                                        php_value max_input_vars 1000
                                                                                                                        php_value memory_limit -1
                                                                                                                        php_value post_max_size 8M
                                                                                                                        php_value session.gc_maxlifetime 1440
                                                                                                                        php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
                                                                                                                        php_value upload_max_filesize 2M
                                                                                                                        php_flag zlib.output_compression Off
                                                                                                                        </IfModule>





                                                                                                                        share|improve this answer













                                                                                                                        I found the most working solution for this problem. Just edit your .htaccess in root folder and write the following code. Nothing else required



                                                                                                                          RewriteEngine on
                                                                                                                        RewriteCond %{REQUEST_URI} !^public
                                                                                                                        RewriteRule ^(.*)$ public/$1 [L]

                                                                                                                        <IfModule php7_module>
                                                                                                                        php_flag display_errors Off
                                                                                                                        php_value max_execution_time 30
                                                                                                                        php_value max_input_time 60
                                                                                                                        php_value max_input_vars 1000
                                                                                                                        php_value memory_limit -1
                                                                                                                        php_value post_max_size 8M
                                                                                                                        php_value session.gc_maxlifetime 1440
                                                                                                                        php_value session.save_path "/var/cpanel/php/sessions/ea-php71"
                                                                                                                        php_value upload_max_filesize 2M
                                                                                                                        php_flag zlib.output_compression Off
                                                                                                                        </IfModule>






                                                                                                                        share|improve this answer












                                                                                                                        share|improve this answer



                                                                                                                        share|improve this answer










                                                                                                                        answered Jan 9 at 6:47









                                                                                                                        AKHIL RAJAKHIL RAJ

                                                                                                                        114




                                                                                                                        114























                                                                                                                            0














                                                                                                                            ##Create .htaccess file in root directory and place code something like below.

                                                                                                                            <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>





                                                                                                                            share|improve this answer




























                                                                                                                              0














                                                                                                                              ##Create .htaccess file in root directory and place code something like below.

                                                                                                                              <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>





                                                                                                                              share|improve this answer


























                                                                                                                                0












                                                                                                                                0








                                                                                                                                0







                                                                                                                                ##Create .htaccess file in root directory and place code something like below.

                                                                                                                                <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>





                                                                                                                                share|improve this answer













                                                                                                                                ##Create .htaccess file in root directory and place code something like below.

                                                                                                                                <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>






                                                                                                                                share|improve this answer












                                                                                                                                share|improve this answer



                                                                                                                                share|improve this answer










                                                                                                                                answered Jan 20 at 9:42









                                                                                                                                Pallav NagarPallav Nagar

                                                                                                                                211




                                                                                                                                211

















                                                                                                                                    protected by Community Mar 11 '16 at 5:30



                                                                                                                                    Thank you for your interest in this question.
                                                                                                                                    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                                                                    Would you like to answer one of these unanswered questions instead?



                                                                                                                                    Popular posts from this blog

                                                                                                                                    Callistus III

                                                                                                                                    Plistias Cous

                                                                                                                                    Index Sanctorum