避开laravel的public文件夹,直接在web服务器中打开root

问题描述:

我正在浏览互联网上所有可能的样本来解决这个问题.还是很头疼.

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_htmlpublic_ftp 文件夹,并将除 public 文件夹之外的整个 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 上更改以下行:

On your public_html/index.php change the following line:

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',

您的网站应该正在运行.

Your site should be running.