This option shows you how to place WordPress in a separate directory, but leave the website URL in the root directory.

wp

wp-admin

wp-includes

wp-content

wp-load.php

… other files

wp-config.php

index.php

.htaccess

What happens in the end: the URL of the site will be, for example, http://example.com, but the files of the WordPress itself will be in the wp subfolder, which is located in the folder that corresponds to our URL. Those. WordPress allows you to install WordPress files in a subdirectory, but the site will run in the root directory.

The process of moving WordPress to its own directory is as follows:

Create a new directory in the site’s root directory. Let’s call it /wp.

Move all WordPress files to the new /wp directory.

Return the moved files: index.php and .htaccess back to the root directory.

Open the index.php file (from the root directory) and change the line in it:

// replace this line

require( dirname( __FILE__ ) . ‘/wp-blog-header.php’ );

// on the

require( dirname( __FILE__ ) . ‘/wp/wp-blog-header.php’ );

Go to “Settings” of the site. The admin area is now located at: http://example.com/wp/wp-admin/.

Change options:

WordPress Address (URL) – Specify the URL where the WordPress files are located: http://example.com/wp.

Blog address (URL) – enter the URL of the site itself: http://example.com.

Ready!

WP core files in a subfolder

For convenience, you can change the WordPress file structure so that the core files (that is, those that are updated when WordPress is updated) will be in a separate folder, for example, in the wp folder, and all other files in the root of the site. Get the following file structure:

wp

wp-admin

wp-includes

wp-load.php

index.php

… other files

… wp-config.php should not be there, otherwise the site will not work!

wp-content

index.php

wp-config.php

.htaccess

For this placement:

Create a wp folder and move all files/folders there except: wp-content and wp-config.php.

Copy the wp/index.php file to the site’s root folder. After copying, change the content of the remaining wp/index.php file to <?php // Silence is golden..

Open the index.php file (in the root of the site) and change the path to the wp-blog-header.php file in it:

// replace this line

require __DIR__ . ‘/wp-blog-header.php’;

// on the

require __DIR__ . ‘/wp/wp-blog-header.php’;

Also, we need to change the paths to the content folder, because we moved the engine, and left the content folder in the root of the site, but WordPress expects it next to the wp-admin, wp-includes folders. You need to specify where exactly the content folder is located. To do this, open the wp-config.php file and add the following lines there (add to the beginning of the file):

// define wp-content directory

$scheme = ( (! empty($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] !== ‘off’) || $_SERVER[‘SERVER_PORT’] == 443 ) ? ‘https’ : ‘http’;

define( ‘WP_CONTENT_DIR’, __DIR__ .’/wp-content’);

define( ‘WP_CONTENT_URL’, sprintf( “%s/wp-content”, $_SERVER[‘HTTP_HOST’] ? “$scheme://{$_SERVER[‘HTTP_HOST’]}” : ” ) );

Or you can without protocol:

define( ‘WP_CONTENT_DIR’, __DIR__ .’/wp-content’);

define( ‘WP_CONTENT_URL’, sprintf( “%s/wp-content”, $_SERVER[‘HTTP_HOST’] ? “//{$_SERVER[‘HTTP_HOST’]}” : ” ) );

The path and URL should end up looking at the wp-content folder.

Note: If you are modifying the structure on an already established site, you will also need to modify the value of the siteurl option in the wp_options database table. There you need to finish off wp, i.e. change from http://example.com to http://example.com/wp.

You can quickly do this in the General settings in the admin panel – now the site address will be different from the WordPress address:

General settings – different Wp and site addresses

Note: after this change, you may see a warning (“PHP Warning”), don’t worry, there’s nothing to worry about, it will appear once and everything will work as it should!

There should be no wp-config.php file in the wp engine folder. If it is there, then it will work, and not the one located in the root of the site. This will cause an error and the site will not work.

There should be no wp-settings.php file in the root folder.

In general, when transferring, it is transferred, but it may happen that you do not transfer files, but copy them to a new folder of the wp engine (for example, when you want to play it safe and copy everything first, check if everything works, and then delete, now unnecessary files) . So, if the wp-settings.php file is located in the root folder, then WP will consider the root folder to be the core folder, and not our new wp folder.

Useful note on the topic: bug with moving the uploads folder

Stage: running the WordPress installation

After the database is created, the files are copied and wp-config.php is created, we need to run the WordPress installation. During installation, the necessary tables will be created in the database and a user will be created – the site administrator.

To start the installation, you need to go to the site (go to the URL):

If the WordPress files are located in the root directory of the server, then the link will be: http://example.com/;

If the WordPress files are located in a subdirectory, then the link will be: http://example.com/blog/, where blog is the name of the subdirectory.

In both cases, you should be redirected to http://example.com/wp-admin/install.php or http://example.com/blog/wp-admin/install.php.

During installation, you will enter the name of the site and your email. Also, during installation, you can “ask search engines not to index the site”, for this, check the box next to this item.

Any information entered can be changed in the admin panel in the future. It will not be possible to change only the user’s login.

Installation problems

Error 1: “error database connection”

If during the installation process an error “crawled out”: “error database connection” (database connection error), then:

Check if the name, logs and password are correct in the wp-config.php file;

Make sure the user you created has permissions to access the WordPress database;

Error 2: “Headers already sent”

If during installation errors like: Headers already sent. You may have made a mistake while editing wp-config.php.