3

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,

enter image description here

KBK
  • 375
  • 1
  • 4
  • 20

7 Answers7

3

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';
Vision Coderz
  • 8,257
  • 5
  • 41
  • 57
3

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.

Community
  • 1
  • 1
Alexey Mezenin
  • 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
1

Add a .htaccess file in root which contains -

RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
Risul Islam
  • 804
  • 1
  • 12
  • 24
1

Yes it is very simple no need to add extra htaccess,

  1. Create a new folder in your laravel project folder.
  2. Name it whatever you like. Example :- source

enter image description here

  1. Move all the files from root into 'source' folder except 'public' folder.

enter image description here

4 . Move all the files from public folder to root.

enter image description here

5 . Change the autoload.php path

6 . Thats all. remove public folder if necessary.

enter image description here

KBK
  • 375
  • 1
  • 4
  • 20
0

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>
Santosh Kumar
  • 1,756
  • 15
  • 24
0

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.

ShuBham GuPta
  • 194
  • 2
  • 9
-1

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

Community
  • 1
  • 1
Akshay Deshmukh
  • 1,242
  • 1
  • 16
  • 31