【问题标题】:Run PHP into *.html extension (mime type) [duplicate]将 PHP 运行到 *.html 扩展名(mime 类型)[重复]
【发布时间】:2014-03-21 15:31:42
【问题描述】:

我有 xampp,我有一个扩展项目 *。 html 和 php 代码有我的本地主机 php 不会解释代码并将其显示为 php,但我想作为 php 代码运行: index.html

 <?php
      $seccion='inicio';
      require_once("idiomas.html");
      require_once("configurador.html");
      require_once("header_scripts_css.html");
    ?>

    <body class="clearfix">
      <header id="header">
        <?php require_once("header.html"); ?>
      </header>
      <?php require_once("slider.html"); ?>
      <div id="centro">
        <?php require_once("central.html");?>
      </div>
      <?php require_once("footer.html"); ?>

【问题讨论】:

  • 您不能在 .html 文件中运行 PHP。
  • @TomKriek 是的,你可以。如果您在正确的位置查找,PHP 将处理您要求它处理的任何文件。
  • @TomKriek:如果您告诉服务器通过 PHP 处理 .html 文件,则可以。
  • 为什么不把文件扩展名改成 *.php 呢?
  • @Tim Cooper 试过这个但在 htaccess 中不起作用认为它与 httpd.conf 和 mime.types 文件有关

标签: php html


【解决方案1】:

你可以添加

AddType application/x-httpd-php .html

进入您的.htaccess 文件,或者您可以修改 apache mod-php5 设置

【讨论】:

  • 如果添加到 htaccess,操作需要确保他的 allowoverride 设置正确。根据您的发行版,最好在 httpd.conf 或 apache2.conf 中更改它以提高安全性。
  • 不工作变量读取为 html 代码包含等。..
  • 您仍然需要包含正确的 php 标签,并在更改配置后确保重新启动您的 apache。
  • 是的,我的 apache 已经重启了
  • 不能再同意 Justin E。最好添加到配置中的 FilesMatch 块中
猜你喜欢
  • 2011-05-14
  • 2013-05-06
  • 1970-01-01
  • 2012-05-19
  • 1970-01-01
  • 2011-09-22
  • 2011-12-01
  • 1970-01-01
  • 2010-11-05
相关资源
最近更新 更多