避免laravel在Web服务器的公共文件夹并打开直接根 [英] Avoid public folder of laravel and open directly the root in web server
问题描述
我要通过所有可能的样本在互联网上解决这个问题。不过这是一个头疼的问题。
I was going through all possible sample on internet to solve this. Still it is an headache.
我只是想避免公共的 www.mylaravelsite.com/public /
并使其像 www.mylaravelsite.com
的根目录。
I just want to avoid the 'public' in www.mylaravelsite.com/public/
and make it like www.mylaravelsite.com
for the root directory.
现在我不希望避免的安全问题,所以我学会了的.htaccess
将是最好的方式。
Now I do not want to avoid the security concern,So I learned .htaccess
would be the best way.
任何解决方案的朋友?
&放大器;提前感谢互动!
& advance thanks for interacting !
推荐答案
让我们假设你有这样的文件夹结构,你的服务器
Let's assume you have this folder structure in your server
.cpanel/
public_html/
public_ftp/
..
而laravel文件夹结构
And the laravel folder structure is
app/
bootstrap/
public/
vendor/
composer.json
artisan
..
您可以创建您的服务器内嵌一个文件夹名称mylaravelsite与的public_html
和 public_ftp
文件夹,复制到它整个laravel应用程序,除了公共文件夹,因为你将全部粘贴就可以了内容的的public_html
,所以你现在有:
You can create a folder name mylaravelsite on your server inline with public_html
and public_ftp
folder, and copy to it the whole laravel application except the public folder because you will paste all of it contents on the public_html
, so you have now:
.cpanel/
public_html/
public_html/packages
public_html/vendor
public_html/index.php
public_html/.htaccess
...
public_ftp/
mylaravelsite/
mylaravelsite/app
mylaravelsite/bootstrap
...
在你的的public_html / index.php文件
更改以下行:
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
到
require __DIR__.'/../mylaravelsite/bootstrap/autoload.php';
$app = require_once __DIR__.'/../mylaravelsite/bootstrap/start.php';
,也不要忘了修改 /mylaravelsite/bootstrap/paths.php
公共道路,你可能会使用它。
and also don't forget to change /mylaravelsite/bootstrap/paths.php
public path, you might use it.
'public' => __DIR__.'/../public',
到
'public' => __DIR__.'/../../public_html',
您的网站应该运行。
这篇关于避免laravel在Web服务器的公共文件夹并打开直接根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!