【问题标题】:Configure Laravel .1 htaccess配置 Laravel .1 htaccess
【发布时间】:2017-02-11 18:57:17
【问题描述】:

我已经安装了 Laravel 5.1 并尝试在共享主机上配置它。 我在项目根目录中添加了 index.php 文件,在公共文件夹中添加了 .htaccess 文件,但仍然得到:

500 Internal server Error

我跑过: composer install.

我已经在.envfile 数据库配置中添加了。

我的项目文件夹名为cms

然后我尝试像这样将.htaccess file 更改为public directory

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

    RewriteEngine On
    RewriteBase /cms/

    # 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}]
</IfModule>
我在project root 中的.htaccess file 是:

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

    RewriteEngine On
     RewriteBase /cms/
#    RewriteBase /home/crewjobe/public_html/
    # 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}]

</IfModule>

我在项目根目录和公共目录中都有 index.php 文件。 公共目录中的 index.php 是从 laravel 安装的。 项目根目录下的 index.php 文件为:

<?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__.' /public'.$uri)) {
    return false;
}

require_once __DIR__.' /public/index.php';

我哪里错了?全新安装 Laravel 时是否有一种标准的配置方式?谢谢。

【问题讨论】:

  • 我从未在 .htaccess 中看到嵌套的 IF .. 不确定这是问题所在,但看起来确实很奇怪。建议将其移出 `if mod_rewrite' 块 # Options -MultiViews
  • 这是用laravel安装创建的..其他部分我改了一点
  • 你怎么知道这个问题与.htaccess有关?错误 500 表明一些 PHP 错误。您的共享主机上的publicpublic_html 目录中是否有error.log?另外,将ini_set('display_errors', 1); error_reporting(-1);添加到index.php并检查是否有详细错误
  • 我检查了服务器错误日志,并且有消息:“/path/to/cms1”可被组写入”和“客户端被服务器配置拒绝:/path/to/public_html/domain_name/。 htaccess"

标签: php apache .htaccess laravel


【解决方案1】:

谢谢@milz,在我检查了服务器错误日志并找到了这些消息之后:

path/to/project/folder/ is writeable by group

并搜索问题,我找到了这个解决方案: Solution

我将项目文件夹权限更改为0644 以及项目/公共文件夹,现在很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2018-12-23
    • 2016-01-05
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2013-10-18
    相关资源
    最近更新 更多