.htaccess|如何将文本或文件附加为某些或所有文件的标头



四处搜索都没有找到.htaccess文件如何编辑/修改某些(.html、.php、.json等(或所有文件。

在本例中,代码/文件作为所有或某些类型文件的头附加

example.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>

要附加的代码/文件内容

<script>console.log(<?php echo __FILE__; ?>);</script>

desired.php

<script>console.log(<?php echo __FILE__; ?>);</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
</body>
</html>

我知道一些.htaccess,但足以改编一个例子,不知道从哪里开始。

注意:如果有人问,我目前-不必要,我认为-代码:

AddType application/x-httpd-php .htm .html
SetEnv TZ America/Mexico_City
php_value date.timezone 'America/Mexico_City'
Options All -Indexes
RewriteEngine On
RewriteRule ^([-a-zA-Z0-9/]+)$ index.php?r=$1

提前谢谢。

使用PHP的auto_prepend_file,显然这只适用于PHP。

将此添加到您的.htaccess(或相应地更改您的php.ini(:

# modify include_path to prepend.php if needed
#php_value include_path .:/var/www/php/include:/usr/share/php
# the template to prepend to your php files
php_value auto_prepend_file prepend.php

prepend.php的内容更改为:

<script>console.log('<?php echo $_SERVER["SCRIPT_FILENAME"]; ?>');</script>

以使用所请求的文件路径而不是CCD_ 4的路径。

最新更新