How to Move the wp-config.php File in WordPress

How to Move the wp-config.php File in WordPress

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: WordPress 5+

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

Create directory in root WordPress

In the root directory we find the file – wp-config.php, and move it to the created directory.

Move to created directory

You should get the following result. The wp-config.php file is located in the hdirectory directory

WP config
WP config

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!

0

More

Leave a Reply

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

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation