【发布时间】:2017-08-08 13:38:33
【问题描述】:
我正在用一个简单的 php 网站模板制作一个 php 网站
这是index.php的样子
require './config.php';
require './functions.php';
//echo 'hello';
run();
run()函数在functions.php中
function run() {
include config('template_path') . '/template2.php';
}
这是 template2.php 文件
include 'header.php';
pageContent();
include 'footer.php';
当我使用 WAMP 服务器在 localhost 中运行该站点时,它可以完美运行,没有任何问题。
但是当我将此项目上传到亚马逊服务器时,服务器返回 HTTP 500 错误。当我评论 require 语句时,页面工作(显示你好)。我是 php 初学者,不知道问题出在哪里,需要帮助。
这是 .htaccess 文件
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L]
配置.php
<?php
/**
* Used to store website configuration information.
*
* @var string
*/
function config($key = '') {
$config = [
'name' => 'Test',
'nav_menu' => [
'home' => 'Home',
'about-us' => 'About Us',
'portfolio-works' => 'Portfolio',
'contact' => 'Contact',
],
'portfolio' => [
[ 'Test','Test', "assets/img/portfolio/test.jpg",'movie'],
['Test','test1', "assets/img/portfolio/test.jpg",'documentary'],
['Test','test2', "assets/img/portfolio/test.jpg",'advertisement'],
],
'template_path' => 'template',
'content_path' => 'content',
'pretty_uri' => true,
'version' => 'v2.0',
'link' => '/peekay',
'about_us' => 'Lorem ipsum',
];
return isset($config[$key]) ? $config[$key] : null;
}
【问题讨论】:
-
require './config.php'; require ('./functions.php');- 只是为了测试,用括号尝试它们。但是,如果您在服务器上有任何错误日志,这将有助于显示问题所在。或者逐行构建页面以查看哪个位失败:) -
你有错误日志吗?
-
页眉和页脚的斜线是不必要的,会破坏您的脚本。当涉及到 PHP 时,斜线开始是针对系统的根目录,而不是您的网站。
-
发生 500 内部服务器错误时,您要做的第一件事就是检查服务器日志文件。
-
@CBroe 但这些都没有抓住重点(没有双关语)
include '/header.php'.. 所以你需要写include 'header.php'或一般./file.php,还要注意require和@987654335 @ 是 not 函数,因此不需要( )。
标签: php