【发布时间】:2017-11-07 23:15:44
【问题描述】:
所以我正在尝试配置我的.htaccess 文件,以便它可以在 HTML 文件中运行 PHP 代码。
当我转到mysite.com/thefile.php 时,它可以正常运行,没有任何问题。如果我去mysite.com/thefile.html 也是一样。但是如果我在 HTML 文件中添加<?php echo "Hello"; ?>,它不会显示任何内容。实际上,当我右键单击“查看源代码”时,它会显示 php 行。
这是我对 .htaccess 文件的尝试:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .html .htm
我也试过了
AddType application/x-httpd-php .php .html .htm
但它显示“500 Internal Server Error”,上面写着:
The server encountered an internal error or misconfiguration and was unable to complete your request.
The most common causes of this problem are errors in the app's .htaccess file or incorrect file or directory permissions preventing the web server from reading the .htaccess file.
More information about this error is available in the app's Apache error log at:
/srv/users/SYSUSER/log/APPNAME/APPNAME_apache.error.log
总的来说,我对 Web 开发还很陌生,我想提一下,除了 .htaccess 文件中的这 2/1 行之外,我没有别的东西。也许我错过了一些行?只是猜测
谢谢大家(如果有的话,谢谢你们!)
【问题讨论】:
-
别这样!你想完成什么?
-
什么意思?我只是想在我的 HTML 文件中显示来自我的数据库的信息
-
从您的 PHP 文件中执行。
-
哪个版本的 apache 和哪个风味/版本的 linux?
-
你需要的是 AddHandler,而不是 AddType。