如何使用 .htm 或 .html 扩展名运行 PHP?

art*_*rax 2 html php

我对 php 编码完全陌生,我的老师告诉我们应该使用 .php 扩展名重命名 PHP 文件才能使其工作。但是我在服务器中有带有 .htm 扩展名的文件,我将其与 Google Analytics 和 Search Console 一起使用,所以现在我不想将扩展名更改为我所有的 5 个五页,因为我会从中造成巨大的混乱。那么有没有一种方法可以将 php 代码插入到我的 html 页面中,并且仍然使用 .htm 扩展名?

谢谢!

小智 5

您想在 .HTM / .HTML 文件中编写 PHP 代码

您所要做的就是将以下几行添加到您的 httpd.conf

    AddType application/x-httpd-php .html
    AddType application/x-httpd-php .htm
Run Code Online (Sandbox Code Playgroud)

note: restart your apache or rehash it so that the configurations take effect