gpt4 book ai didi

php - 在 Apache 服务器上找不到 Laravel 5.1 404

转载 作者:行者123 更新时间:2023-12-05 08:23:36 26 4
gpt4 key购买 nike

我目前已经将 laravel 5.1 应用程序托管到我的 1and1.com 服务器上,我的所有路由都面临 404 not found 错误,除了根路由,即 www.example.com/server/

根路由正在处理 get 请求,但所有其他路由都以 404 not found 出现,在本地主机中一切正常。

我的应用文件夹结构:

  • -example.com

    • -服务器
      • 应用
      • 数据库
      • 配置
      • 存储
      • .环境
      • .htaccess
      • index.php
      • server.php

如您所见,我已删除默认的 laravel 公用文件夹并将内容移至根目录。

我的.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}] RewriteCond %{REQUEST_URI} !^ RewriteRule ^(.*)$ /$1 [L] </IfModule>

我的 Index.php

<?php

/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.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__.'/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__.'/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);

Server.php

/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.''.$uri)) {
return false;
}

require_once __DIR__.'index.php';

Routes.php

Route::get('/', function(){
echo'test';exit();
});//test

Route::get('/s', function(){
echo'testss';exit();
});//test

现在,如果您看到第一条路线工作正常,但当我执行 www.example.com/server/s 时,会出现 404 not found。

最佳答案

如果您的项目迁移到新服务器,可能是因为您使用默认项目文档根配置,因此默认情况下它可能无法读取您的 .htaccess 文件。您需要将 /etc/httpd/conf/httpd.conf 中的 AllowOverride 选项从“None”更改为“All”(示例)选项值(如果是 centos):

<Directory /var/www/html/public>
...
AllowOverride All
...
</Directory>

然后重新加载您的服务器以应用更改

sudo service httpd reload

关于php - 在 Apache 服务器上找不到 Laravel 5.1 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39178272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com