duanfei9278 2017-06-06 19:36
浏览 122
已采纳

初学者/如何配置我的.htaccess文件,以便它在我的HTML文件中运行PHP?

So I'm trying to configure my .htaccess file so that it can runs the PHP code inside the HTML files.

When I go to mysite.com/thefile.php, it runs it correctly without any problem. Same if I go to mysite.com/thefile.html. But if I add <?php echo "Hello"; ?> inside the HTML file, it doesnt display anything. In fact, when I right click "View source code", it displays the php lines.

Here's what I tried with my .htaccess file:

RemoveHandler .html .htm

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

I also a tried with just

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

But it displays a "500 Internal Server Error" that says:

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

I'm quite new to web development in general, and I want to mention that, except from these 2/1 lines in the .htaccess file, I have nothing else. Maybe I'm missing some lines in it? Just a guess

Thanks guys (and gals if they exist!)

  • 写回答

1条回答 默认 最新

  • duan5801 2017-06-06 19:45
    关注

    With Ubuntu/Apache 2.4.x, in your /etc/apache2/mods-enabled/php7.1.conf or equivalent, you could add:

    <FilesMatch ".+\.html$"> SetHandler application/x-httpd-php </FilesMatch>

    (But you shouldn't do this at all! Use .php files for PHP code.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记