Auto Prepend and Append PHP Files using htaccess

By Avinash

February 01, 2012Tips & Tricks3 Comments

This article is about to explain the trick to auto append and prepend the php file using htaccess file. Surprised?

Normally all project have some files which needs be included in all files of your project. Or there can be some files which needs to included at the starting of page execution and some file which needs to be included at the end of each page.

In these cases you can write these two lines in your .htaccess file which will helps you for sure.

Prepend File using .htaccess

You can write below code in your .htaccess file for the same.

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

Append File using .htaccess

You can write below code in your .htaccess file for the same.

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

Conclusion

This trick will be useful for the file which has all your functions defined you can prepend this file and for the file like footer you can add this as a append file using this trick.

You can refer to articles related to htaccess tricks at this category, also you can subscribe to our RSS feed using your email address.

Share This Article

  • Bert Struik

    Some service providers block .htaccess calls to auto-append, generating a 500 error.

    • http://www.xpertdeveloper.com Avinash

      Yes true

      • yatin

        how to enable auto_prepend_file in .htaccess