【发布时间】: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 错误。您的共享主机上的public或public_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