I'm using Laravel 5.3 is there a easy way to remove public from URL? is it necessary to add a htacces. when I change the htacces it is getting a n error like below,
7 Answers
copy both htaccess and index.php file from public folder to root directory and then change root index.php code as below
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
- 8,257
 - 5
 - 41
 - 57
 
- 
                    3It's too risky. It makes your composer.json, .env and others sensitive information accessible via browser. Best practice is to set vhost to /public. – Mahfuzul Alam Oct 18 '16 at 04:58
 - 
                    @MahfuzulAlam.Thanks for notifying in comment – Vision Coderz Oct 18 '16 at 05:02
 - 
                    I'm sorry, but I have to say this. It's a really bad advice since if you do that, you'll catch a lot of errors during development and whole you app code will be open to the web. – Alexey Mezenin Oct 18 '16 at 05:06
 - 
                    @AlexeyMezenin. i hope he is using localhost otherwise he would have pointed domain to public folder itslef – Vision Coderz Oct 18 '16 at 05:08
 
After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
https://laravel.com/docs/5.3/installation#configuration
Do not edit .htaccess or Laravel related files, just point web server to a public directory instead of Laravel project directory:
DocumentRoot "/path_to_laravel_project/public"
<Directory "/path_to_laravel_project/public">
Then restart Apache.
- 1
 - 1
 
- 158,981
 - 26
 - 290
 - 279
 
- 
                    This is the correct approach but Latest XAMPP (32-bit) on Windows 7 is not playing nicely. So, my team is implementing the Accepted answer given above. – Mohal Dec 22 '17 at 10:34
 
Add a .htaccess file in root which contains - 
RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
- 804
 - 1
 - 12
 - 24
 
Yes it is very simple no need to add extra htaccess,
- Create a new folder in your laravel project folder.
 - Name it whatever you like. Example :- source
 
- Move all the files from root into 'source' folder except 'public' folder.
 
4 . Move all the files from public folder to root.
5 . Change the autoload.php path
6 . Thats all. remove public folder if necessary.
- 375
 - 1
 - 4
 - 20
 
In the root directory create a .htaccess file and put the following in it
<IfModule mod_rewrite.c>
   RewriteEngine On 
   RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
- 1,756
 - 15
 - 24
 
Even above solution(s) work(s) for you,but I would recommend 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.
 
-you have to configure apache for user not access .env, git files , config folder's file    
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.
- 194
 - 2
 - 9
 
Copy all files and folder from public folder to root folder and edit your .htaccess file as
 <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule> 
And dont forget to change the paths in index.php file. For details refere following links
Installing Laravel in a subfolder
https://ellislab.com/forums/archive/viewthread/151342/#734511
- 1
 - 1
 
- 1,242
 - 1
 - 16
 - 31
 




