akshaykumar6
akshaykumar6

Reputation: 2257

Remove "/public" from Laravel route

I have the project URL as -

http://localhost/project-name/user/public/xxx

I want to change it to -

http://localhost/project-name/user/xxx

I have tried the usual solution available on internet but still no luck. These are htaccess files after going through few solution.

1. project-name/.htaccess

Options -MultiViews

RewriteEngine On
# Check what redirect trailing slash does
# Redirect Trailing Slashes...

# Handle Front Controller...
RewriteRule ^(.*)$ public/$1 [L]

2. project-name/public/.htaccess

Options -MultiViews

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

What is the exact solution for this problem?

Upvotes: 1

Views: 951

Answers (1)

Carter
Carter

Reputation: 1260

Since you don't have permissions to point virtual host to your laravel public folder, I would suggest you:

For Laravel 5, 1) move all your files in the public folder into project root, public folder is not needed anymore and 2) update the original index.php like so:

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

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

For Laravel 4, you also need to edit value of "public" in the array in /bootstrap/paths.php.

This should achieve what you want. Hopes this helps.

Having said that, try to host your app in VPS where you have full control on everything :)

Upvotes: 2

Related Questions