【问题标题】:how to parse php file inside of html file如何在html文件中解析php文件
【发布时间】:2019-01-11 22:41:54
【问题描述】:

有人可以帮我配置我的httpd.conf 服务器文件,以便我可以执行简单的 php 代码作为 .html 文件运行吗?

浏览器不输出任何内容或只是空白。 (例如)

php 版本 - 7.2.8 服务器版本 - Apache/2.4.34 (Fedora)

【问题讨论】:

  • 通常浏览器可以解释 html 而你的服务器可以解释 PHP。所以我不明白这个问题。也许展示一个你需要做什么的例子。是如何为 PHP 配置 Apache 的吗?

标签: php apache2.4


【解决方案1】:

在您的项目目录中创建 .htaccess 文件并使用以下代码:

RewriteEngine On
RewriteRule index.html index.php

用你的脚本文件名替换索引

【讨论】:

  • 这个简单的解决方案奏效了!救了我一些挫折。感谢您的建议、建议和宝贵的回复!
【解决方案2】:

您应该将您的 html 文件保存为 php 格式或使用 .htaccess 以使所有 .html 页面以 .php 文件运行:
第一种方式:

file.html 大多数转换为 file.php

你最常运行你的网络服务,然后用逻辑地址打开你的文件 http://localhost/file.php

第二种方式: 在您网站的根目录创建一个 .htaccess 文件并添加以下行:

[Apache2 @ Ubuntu/Debian:使用这个指令]

AddType application/x-httpd-php .html .htm

或者,来自下面的评论:

AddType application/x-httpd-php5 .html .htm

如果您将 PHP 作为 CGI 运行(可能不是这种情况),您应该改为:

AddHandler application/x-httpd-php .html .htm 

Using .htaccess to make all .html pages to run as .php files

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 2012-07-09
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多