Laravel4 remove public from URL

2019-03-03 10:11发布

I am working on laravel project and deploye it on Hostgator server.

Everything is working fine but I don't want to run my site like www.xyz.com/public. I want to remove /public from the url. For this, I am following this link (Method II : Moving the contents of public folder to root directory). After this my Home page is working fine on www.xyz.com. But when I try to access www.xyz.com/about or www.xyz.com/admin it returns a 404 page, "not found error".

I am new to laravel can someone suggest me what should I do to solve this problem.

标签: laravel-4
1条回答
冷血范
2楼-- · 2019-03-03 10:34

Just follow below steps:

1.Create a folder myappnamebase in your document root folder

2.Put all your contents of the application except the public folder content to myappnamebase folder

3.Put all your public folder content in public_html folder

Then bring the following changes:

Inside public_html->index.php

instead of

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

add

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

instead of

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

add

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

Inside myappnamebase->bootstrap->paths.php do editting so that it looks like following

'app' => __DIR__.'/../myappnamebase/app',

'public' => __DIR__.'/../public',

'base' => __DIR__.'/../myappnamebase',

'storage' => __DIR__.'/../myappnamebase/app/storage',

Finally dont forget to upload .htaccess in the public_html folder. It should look like following:

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

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]

查看更多
登录 后发表回答