1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Include a file globally with Auto Prepend File
This guide explains how to specify a file that will be loaded even before the desired page or at the beginning of every PHP script executed on your server, included as if it had been called with the 'require()' function, but more broadly using the PHP "auto_prepend_file" directive.
For example, to declare the headers of a website, you can create a file called headers.php that contains PHP header() functions and is prepended at the beginning of each PHP file:
- via a .user.ini file (specific to a folder)
- or via the site's configuration in the Manager (global), as explained below
Including a File Globally from the Manager
- open the Manager (manager.infomaniak.com)
- go to Web Hosting
- click on the hosting/domain name concerned
- under Sites, at the bottom, click on the domain name of the site concerned
- click on the Advanced Settings button
- under the Apache tab, enter the path to the file to include
- save
After defining this directive, all PHP pages on your server will automatically include the specified file before executing their own code.
The headers defined in an .htaccess file are valid only for non-PHP content (i.e., static content).
We use php-fpm, which receives different headers via Apache fast_cgi. In the CGI RFC, the "Strict-Transport-Security" header is not part of the headers passed via CGI, and the Apache documentation httpd.apache.org/docs/2.2/howto/cgi.html confirms this. Also, read https://www.ietf.org/rfc/rfc3875.