当前位置: 首页 > 知识库问答 >
问题:

在子域上托管Laravel时的HTTP错误500?

宋耀
2023-03-14

我遵循了以下步骤:http://laravel.io/forum/12-29-2015-hosting-laravel-5-on-subdomain

/家-

服务器上的结构:

公共网页-

我的htaccess看起来像:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

我得到HTTP错误500。

我不想将公用文件夹中的所有文件都移动到主目录,因为它可能会使许多人能够访问其他文件,从而危及安全。那么使用laravel就没有意义了。

有没有更简单的方法将子域指向laravel-ecommerce/Public文件夹。

谢谢

编辑:

我在hostgator上主持节目。

我ndex.php:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/

require __DIR__.'/../../laravel-ecommerce/bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../../laravel-ecommerce/bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

自动加载。php

<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../laravel-ecommerce/vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/

$compiledPath = __DIR__.'/../laravel-ecommerce/cache/compiled.php';

if (file_exists($compiledPath)) {
    require $compiledPath;
}

应用程序。php

<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__.'/../laravel-ecommerce/')
);

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;

共有2个答案

公孙宗清
2023-03-14

由于. htaccess文件不在根目录中,因此必须使用ReWriteBase。添加重写基础/后重写引擎打开

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On
RewriteBase /

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
傅博瀚
2023-03-14

尝试为子域重定向htaccess代码:

#htaccess redirects for subdomains
RewriteRule ^subdomaindirectory$ subdomaindirectory/ [R,L] 
RewriteRule ^subdomaindirectory/(.*)$ subdomaindirectory/$1 [L]

注意用文件夹名称替换子域目录。

此外,您能把您的服务器错误日志吗?

 类似资料:
  • 首先,我必须说,这个问题已经被问了几千次了。我使用以下工具创建了我的Laravel 5.5项目: 我没有给这个项目增加任何东西。项目在本地运行没有问题。当我想在共享托管网站上托管项目时,问题就来了(我正在使用infinityfree.net) Laravel 5.5的最低PHP版本:PHP 我的共享托管站点php版本:php版本7.0。19 我所做的唯一更改是: > 我复制了公共文件夹的内容到我的

  • 我在AWS/S3上与其他域名注册商建立了许多静态站点;但是,google域给我带来了一些问题。 我采取的步骤: -在S3/AWS上: > 已创建桶domainname.org 通过添加index.html启用静态网站托管 已将index.html和相关文档上载到存储桶 创建桶www.domainname.org以重定向到桶domainname.org 为domainname.org创建了桶策略,如

  • 我曾尝试在CentOS Web Panel(CWP)中使用应用程序的单个帐户托管laravel 5.1应用程序。我不想在一个帐户中托管多个站点。我已经在中设置了我的站点 我的结构是 我已经尝试使用这些解决方案: https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-la

  • 我在本地环境中创建了一个带有Laravel 7的网络应用程序,它有一个选项,用户可以上传和更改他们的个人资料图像。它在当地环境中运行良好。最近我把这个项目上传到一个子域下的实时服务器上。我把所有公共文件放在子域文件夹中,其他文件放在根文件夹中。像这样。 文件结构 现在当我运行 它将文件/public/images中的图像上传到hello中。实例com/images 文件上载代码:

  • 我有我的节点。具有依赖项的js应用程序 } 它在我的本地主机上运行良好 当我在heroku上托管我的节点应用程序时,我遇到了以下错误。 TypeError:对象#在对象上没有“randomBytes”方法。MemoryStore上的uid(/app/node_modules/express/node_modules/connect/lib/utils.js:121:17)。在对象的generate

  • 我有一个组件调用我的服务,如下所示: authservice调用如下所示: 这导致http帖子永远不会被触发,并立即与上面的图像发生错误。如果我删除了switchMap,只返回服务中的可观察值,然后在组件中订阅它,则调用成功。 我错过了什么吗?我对rxjs相对较新,所以我不确定我是否误解了什么,但任何帮助都将不胜感激。 编辑:我还能够将switchMap移动到组件中,做我需要的事情,然后在最后调用