Laravel4从URL移除public [英] Laravel4 remove public from URL
问题描述
我正在研究laravel项目,并将其部署在Hostgator服务器上.
I am working on laravel project and deploye it on Hostgator server.
一切正常,但是我不想像www.xyz.com/public
那样运行我的网站.我想从网址中删除/public
.为此,我正在关注此链接(方法II:将公用文件夹的内容移至根目录).之后,我的主页在www.xyz.com
上运行良好.但是,当我尝试访问www.xyz.com/about
或www.xyz.com/admin
时,它返回404页面,未找到错误".
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".
我是laravel
的新手,有人可以建议我该怎么做才能解决此问题.
I am new to laravel
can someone suggest me what should I do to solve this problem.
推荐答案
只需执行以下步骤:
1.在文档根文件夹中创建一个文件夹myappnamebase
1.Create a folder myappnamebase
in your document root folder
2.将应用程序的所有内容(公用文件夹内容除外)放到myappnamebase文件夹中
2.Put all your contents of the application except the public folder content to myappnamebase folder
3.将所有公用文件夹内容放入public_html
文件夹
3.Put all your public folder content in public_html
folder
然后带来以下变化:
在public_html-> index.php内部
Inside public_html->index.php
代替
require __DIR__.'/../bootstrap/autoload.php';
添加
require __DIR__.'/../myappnamebase/bootstrap/autoload.php';
代替
$app = require_once __DIR__.'/../bootstrap/start.php';
添加
$app = require_once __DIR__.'/../myappnamebase/bootstrap/start.php';
在myappnamebase-> bootstrap-> paths.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',
最后不要忘记在public_html
文件夹中上传.htaccess.它应该如下所示:
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]
这篇关于Laravel4从URL移除public的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!