为了解决这个问题,我在网上翻遍了所有可能的样本.不过,这仍然是一个令人头疼的问题.

I just want to avoid the 'public' in www.mylaravelsite.com/public/ and make it like www.mylaravelsite.com for the root directory.

现在我不想回避安全问题,所以我知道.htaccess会是最好的方式.

Any solution friends ?

& advance thanks for interacting !

推荐答案

Let's assume you have this folder structure in your server

.cpanel/
public_html/
public_ftp/
..

laravel文件夹 struct 是

app/
bootstrap/
public/
vendor/
composer.json
artisan
..

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
...

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

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

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

to

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

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

另外,不要忘记更改/mylaravelsite/bootstrap/paths.php个公共路径,您可能会使用它.

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

to

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

你的网站应该正在运行.

Laravel相关问答推荐

URL类图中的循环关系

当两个外键都在同一个表上时创建直通关系

如何在 Laravel 中使用内存数据库的完整测试套件之前迁移和 seeder ?

错误try 访问 null 类型值的数组偏移量laravel 5.8.26 Php 7.4.2

如何修复无效请求(不支持的 SSL 请求)

Laravel 将 JSON 转换为数组?

在 Laravel 5 中扩展请求类

laravel 5中的配置缓存导致找不到视图

如何在 Laravel 中实现自己的 Faker 提供程序

如何在 Laravel Eloquent 中 Select 某些字段?

laravel 搜索多个以空格分隔的单词

如何在 php Laravel 中对关联数组进行排序

未找到列:1054 未知列 laravel

将 Laravel 集合附加到另一个集合

如何在 Laravel 视图中找到当前语言?

Laravel 应用程序连接数据库时速度很慢

在我的编辑器中管理上传文件的最佳方式?

Laravel 在域和子域中共享 cookie 检测问题

使用 Queue::fake() 测试监听器

如何在 Laravel 5 中验证 RESTful API?