Laravel 5.5共享主机从/ public更改为/ public_html - 部分工作

问题描述 投票:1回答:1

我已阅读[Laracasts thread](https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5?page=2)上的一个帖子,但不确定当前正确的解决方案,特别是对于Laravel 5.5? (注意:我无权更改任何配置服务器端,除了选择使用哪个Php版本 - 以及少数ssh命令[我可以访问的有限目录])。

我的情况:使用共享主机,所以我的公共目录是

/home/{mycomputer generated user}/public_html/

最初我将Laravel目录上传到public_html文件夹。该系统使用了将URL www.mydomain.xyz/public/作为root的URL的怪癖。

然后我尝试了这种修改路径的方法:

  1. 将所有文件移出public_html文件夹,使其与public_html文件夹具有相同的级别。

所以文件夹(在我以前的laravel文件夹中)驻留在这里:

/home/{mycomputer generated user}/

  1. /public的内容复制到/public_html
  2. 编辑了index.php/public_html内容

来自:require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php';

TO:require '/home/{my user}/vendor/autoload.php'; $app = require_once '/home/{my user}/bootstrap/app.php';

现在我的主页加载正常(欢迎视图),如我的web.php路由文件中所述

Route::get('/', function () { return view('welcome'); });

===================================================================

我的问题:

但是,任何其他路线都会失败

“未找到

在此服务器上找不到请求的URL /{legitimate route}

我需要做的其他任何步骤?

我试过:1。加载一个存放在public_html文件夹中的简单jpg文件,工作正常(mydomain.xyz/test.jpg)

  1. 更改了root的路由以返回无效视图,这引发了Laravel错误

Route::get('/', function () { return view('test'); });

"InvalidArgumentException View [test] not found."

  1. 尝试使用闭包(而不是使用控制器)来返回合法的视图 - 没有用

Route::get('/main', function () { return view('tempview.main'); });

我错过了什么? .htaccess有变化吗?另一个我需要改变公共道路的地方?

.htaccess laravel-5.5 public-html
1个回答
1
投票

我在回答取决于你的尝试:

步骤1.将index.php和.htaccess从public复制到public_html,这意味着进入根文件夹。

步骤2.将index.php修改为public_html文件夹

From: require __DIR__.'/../vendor/autoload.php';

To: require __DIR__.'/vendor/autoload.php';

From: $app = require_once __DIR__.'/../bootstrap/app.php';

To: $app = require_once __DIR__.'/bootstrap/app.php';
© www.soinside.com 2019 - 2024. All rights reserved.