【发布时间】:2016-05-21 12:40:18
【问题描述】:
拜托,我正在尝试在共享主机上托管 Laravel 5。
当我访问 www.example.com/my_app_name 时,页面加载正确。 但是,子文件夹返回 404 错误。例如www.example.com/my_app_name/any_sub_folder 或 www.example.com/my_app_name/auth/login 都返回 404 错误。
shared_hosting_root
|--other_folders (not accessible via web domain)
|--applications (not accessible via web domain)
|--my_app_name
|--app
|--GoPublic.php <--I created this
|--bootstrap
|--config
|--database
|--public <--copied content to public_html
|--assets
|--index.php
|--resources
|--storage
|--tests
|--vendor
|--public_html
|--my_app_name
|--assets
|--index.php <-- I pointed here
我创建了一个新文件:shared_hosting_root\applications\my_app_name\app\GoPublic.php
<?php namespace App;
class GoPublic extends \Illuminate\Foundation\Application
{
/**
* Get the path to the public / web directory.
*
* @return string
*/
public function publicPath()
{
return $this->basePath.DIRECTORY_SEPARATOR.'../../public_html/my_app_name';
}
}
我像这样编辑了 bootstrap\app.php:
<?php
/* -- remove/comment this original code
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
-- until here */
/* -- add this new code -- */
$app = new App\GoPublic(
realpath(__DIR__.'/../')
);
我像这样编辑了 public\index.php: 我改变了这个:
require __DIR__.'/../bootstrap/autoload.php';
到
require __DIR__.'/../../applications/my_app_name/bootstrap/autoload.php';
也改变了这一点:
$app = require_once __DIR__.'/../bootstrap/app.php';
到
$app = require_once __DIR__.'/../../applications/my_app_name/bootstrap/app.php';
然后我将 applications\my_app_name\public 中的内容复制到 public_html\my_app_name 中。
我按照本教程中强调的步骤操作:http://blog.kongnir.com/2015/09/25/setting-up-laravel-5-on-shared-hosting-server/
问题又来了:
我可以访问 www.example.com/my_app_name。
但我在 www.example.com/my_app_name/any_sub_folder 甚至登录重定向 www.example.com/myapp_name/auth 上收到 404 错误 /登录
我做错了什么?请帮忙。 谢谢。
更新 www.example.com/my_app_name/sub_folder 返回 500 内部服务器错误 我在 public_html 目录中的 .htaccess 文件:
# Do not change this line.
RewriteEngine on
# Change example.com to your domain name
# RewriteCond %{HTTP_HOST} ^(www.)?schoolsmart.com.ng$
# Change your_app_name to the subfolder name
# RewriteCond %{REQUEST_URI} !^/wbs/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change your_app_name to the subfolder name
# Change example.com to your domain name
# RewriteRule ^(.*)$ /wbs/$1
# RewriteCond %{HTTP_HOST} ^(www.)?schoolsmart.com.ng$
# RewriteRule ^(/)?$ wbs/index.php [L]
RewriteCond %{REQUEST_URI} !^wbs
RewriteRule ^(.*)$ wbs/$1 [L]
【问题讨论】:
-
example.com/my_app_name/index.php/any_sub_folder有什么收获吗? -
我以前回答过这个问题。请按照此处的步骤操作:stackoverflow.com/a/34175815/4159199
-
谢谢@VishalSh 我按照您链接中的步骤操作,我收到 www.example.com/my_app_name/any_subfolder 的 503 错误。但是,ww.example.com/my_app_name/index.php/any_sub_folder 请为我的 .htaccess 代码查找我更新的问题。谢谢。
-
访问:
example.com/my_app_name/index.php/any_sub_folder会得到什么? -
当我尝试访问
example.com/my_app_name/index.php/any_sub_folder时,我得到PHP Fatal error: Class 'Illuminate\View\Expression' not found in /home/schoolsm/applications/wbs/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 215。请帮忙
标签: laravel laravel-5 shared-hosting