The wp-config.php file, which is located in the root directory of your site, contains important information, access to which should be limited to prying eyes. To hide the wp-config.php file, you need to move it to another directory so that attackers cannot find it.
Go to the root directory where the WordPress site content management system files are stored. Create a new directory for example – hdirectory
In the root directory we find the file – wp-config.php, and move it to the created directory.
You should get the following result. The wp-config.php file is located in the hdirectory directory
We return to the WordPress root directory, and since the wp-config.php file has been moved to the hdirectory directory, we need to create a new wp-config.php file. After creating the file, open it in a text editor.
In the new wp-config.php file we add the following code, in which we indicate the path to the old WordPress configuration file, in our case it is hdirectory/wp-config.php
<?php // Absolute path to the WordPress directory if ( ! defined( 'ABSPATH' ) ) { define('ABSPATH', dirname(__FILE__).'/'); } // Location of the configuration file wp-config.php require_once(ABSPATH.'hdirectory/wp-config.php'); ?>
Save the changes made.
That’s all. Go to the site, if everything opens, you did everything right!