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

7 Answers 7

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'; 
Sign up to request clarification or add additional context in comments.

4 Comments

It's too risky. It makes your composer.json, .env and others sensitive information accessible via browser. Best practice is to set vhost to /public.
@MahfuzulAlam.Thanks for notifying in comment
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.
@AlexeyMezenin. i hope he is using localhost otherwise he would have pointed domain to public folder itslef
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.

1 Comment

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

Add a .htaccess file in root which contains -

RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] 

Comments

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

Comments

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> 

Comments

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.

Comments

-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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.