In this tutorial, we will explain how to set up custom .htaccess files for PHP settings. Setting up custom .htaccess files for PHP settings lets you configure PHP directives on a per-directory basis without modifying the main server configuration.
Let us follow the steps –
- Log in to your hosting account via SSH.
- To create a .htaccess file in your website’s document root directory, use a text editor.
- On the other hand, if you wish to set PHP settings for a particular subdirectory, create the .htaccess file in that subdirectory.
- The .htaccess file contents must not be noticeable to the public for some security reasons. For this, enter the following lines into the .htaccess file-
# Prevent Apache from serving .ht* files:
<FilesMatch “^\.ht”>
Order allow,deny
Deny from all
</FilesMatch> - Save the changes and exit the text editor. You are now ready to add specific PHP directives to the .htaccess file.
That is it! I hope you grasped everything well. If you want to explore more informative articles, please visit our Knowledge Base section.
You may also check out our article on setting up the PHP script memory limit in a .htaccess file.