问题
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