四处搜索未发现.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>
使用请求的文件路径代替prepend.php
的路径。