PHP append and prepend in htaccess

痞子三分冷 提交于 2020-01-06 08:16:00

问题


In every single one of my php files I have to do:

<?php require_once('file.php'); ?>

I've been doing a Google research and found that I could use the .htaccess to append or prepend any php file or any other files I need in each of my other files like this:

php_value auto_prepend_file "/real/path/to/file/file.php"
php_value auto_append_file "/real/path/to/file/file.php"

I'm a novice and have not yet played around too much with the .htaccess. Also, I've read that messing with .htaccess can wreak havoc to my website, I haven't tried it out.

My question here is this. I also have jQuery files in my application, if the .htaccess is going to append/prepend the file.php in each and every file, without even trying it out I know it's going to include my stylesheets, my log files, etc. Is there a way make exclusions to files where I don't want file.php to be appended/prepended?


回答1:


you can disable it in specific folders. How can I disable auto_prepend in specific folders using htaccess?

If you want to conditionally disable it in certain files, you can have a conditional statement in your append.php where it doesn't echo whatever it is that it normally does, if the filename matches a certain condition You can use _____FILE_____ directive to get the current file, and you can have a condition check

<?php
if(__FILE__!="..yourfile..")
{
?>

<link rel="stylesheet" href="...">
...

<?php
}
?>

and so on



来源:https://stackoverflow.com/questions/17016629/php-append-and-prepend-in-htaccess

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!