【问题标题】:How to allow execution of PHP in HTML file using .htaccess如何允许使用 .htaccess 在 HTML 文件中执行 PHP
【发布时间】:2019-12-26 03:07:25
【问题描述】:

我想将 .html 文件作为 .php 运行,但似乎无法正常工作。我尝试将以下所有内容添加到我的 .htaccess 文件中,一次一个。以下似乎都不起作用。

AddType application/x-httpd-php .html .htm
AddHandler application/x-httpd-php5 .html .htm
AddType application/x-httpd-php72 .html .htm
AddHandler application/x-httpd-php5 .html .htm
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
<FilesMatch "\.html$">
 ForceType application/x-httpd-php
</FilesMatch>
AddHandler fcgid-script .html
FCGIWrapper /usr/local/cpanel/cgi-sys/php5 .html
Options +ExecCGI
 AddType application/x-httpd-php .php .html
 AddHandler x-httpd-php5 .php .html

我知道 PHP 可以工作,因为我能够创建一个文档 .php 并查看 网站上使用的版本:

<?php
echo 'Current PHP version: ' . phpversion();
?>

它返回:“当前 PHP 版本:7.2.21”

一些值得注意的信息:我在 Bluehost 上托管网站,而 .htaccess 文件目前看起来像这样:

# Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

【问题讨论】:

标签: php html .htaccess web bluehost


【解决方案1】:

你试过了吗?

RewriteRule ^([^\.]+)$ $1.html [NC,L]

看看:https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

【讨论】:

  • 这不是问题
猜你喜欢
  • 2016-10-27
  • 1970-01-01
  • 1970-01-01
  • 2014-08-10
  • 1970-01-01
  • 2012-08-10
  • 2014-01-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多