Tips & Tricks

Auto Prepend and Append PHP Files using htaccess

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 [code].htaccess[/code] file which will helps you for sure.

Prepend File using .htaccess

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

[cc lang=”apache”]
php_value auto_prepend_file “/real/path/to/file/file_name.php”
[/cc]

Append File using .htaccess

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

[cc lang=”apache”]
php_value auto_append_file “/real/path/to/file/file_name.php”
[/cc]

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.

Shares:
  • Bert Struik
    Bert Struik
    February 16, 2013 at 6:49 am

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

    Reply
    • Avinash
      February 16, 2013 at 8:18 am

      Yes true

      Reply
      • yatin
        yatin
        December 24, 2013 at 4:30 pm

        how to enable auto_prepend_file in .htaccess

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *