Parse HTML as PHP

前端 未结 2 476
忘掉有多难
忘掉有多难 2020-11-27 23:03

Are there any security / performance concerns if we set the Apache web server to configure Apache to handle all HTML as PHP? I was specifically referring to:

<
相关标签:
2条回答
  • 2020-11-27 23:59

    The more files the server determines it needs to pass through the PHP interpreter, the more overhead involved, but I think this goes without saying. If your site does not have ANY pages with plain HTML, then you're already paying all the performance penalties that you could possibly pay - adding HTML to the list is no different in this case than simply renaming all the files to have a .php extension.

    The real performance penalty would come if you do have plain HTML pages - the server will needlessly pass these pages to PHP for interpretation when none is necessary. But even then, it isn't dramatic - the PHP interpreter won't be needed for those HTML pages, so it won't do anything aside from determining that it doesn't need to do anything. This has a cost, but it isn't significant.

    Now, if we're talking high-volume here, every little bit of performance matters and this would not be a practicable solution. For low- to mid-volume sites, however, the performance penalty would be nill.

    If this is a one-time change and there are a limited number of files that are affected, then it may be more conservative to use a FilesMatch directive.

    <FilesMatch "^(file_one|file_two|file_three)\.html$">
      AddType application/x-httpd-php .html
    </FilesMatch>
    
    0 讨论(0)
  • 2020-11-28 00:00

    I disagree with Tuga. I don't think you should make this change for all your files. Anytime you deal with security, you should try to control the environment. Doing it only for one file is probably the safest. You could do something like

    <FilesMatch "^file_name\.html$">
    AddType application/x-httpd-php .html
    </FilesMatch>
    

    This will only match file_name.html and process it as .php where it is much safer to do this than treat ALL .html files as php.

    0 讨论(0)
提交回复
热议问题