我在使用一些 php 代码的网站上遇到了一些问题。
我的网站主要使用html和php。我只是使用 php include 语句,而不是在每个页面的顶部重复大量脚本行:
<?php include('main.php'); ?>
我的网站上有一个本地 WAMP 服务器以及 html 和 php 文件的混合体。
当我在本地运行所有内容时,一切都运行得很好,并且“include”语句有效。
但是,当我将所有内容上传到托管在 goDaddy 上的网站时,include 语句仅适用于 .php 文件内。如果我在 .html 文件中使用它,它会失败。它只是不包含任何内容。
我看到一些帖子说可以通过使用 .htaccess 文件来解决这个问题。目前我的网站上还没有。我确实尝试将一个上传到根目录,但唯一的效果是,当我单击页面时,它会显示一个“另存为”对话框。
我猜测要么我的语法错误,要么我走错了路来解决这个问题。
下面是我的 .htaccess 文件的内容。关于如何让 include 语句在 .html 文件中工作的任何想法都会很棒。谢谢。
#
# Server root folder www .htaccess
# This file provides server security limiting access to the localhost only.
# Comment next four lines to deactivate. (Allows external access)
#
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
# Allow from ::1
AddType application/x-httpd-php .html .php .htm
# To allow execution of cgi scripts in this directory uncomment next two lines.
# AddHandler cgi-script .pl .cgi
# Options +ExecCGI +FollowSymLinks
# Activate this section to use the Private Server Feature!
# Defaults: Username - root; Password - root
# Note AuthUserFile: File path is relative to server root
# To lock server, uncomment the next 4 lines. (A name and password is required)
#AuthName "Uniform Server - Server Access"
#AuthType Basic
#AuthUserFile ../../../htpasswd/www/.htpasswd
#Require valid-user
最佳答案
尝试使用这个:
AddHandler x-httpd-php5-cgi .html
请参阅此处:http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler
关于html - 使用 php 包含在 html 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16041729/