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.)

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

报告相同问题?