Moving WordPress from Root to own directory and back

Moving WordPress from Root to own directory and back

Contents

Most people want their WordPress site to load from the main web address (e.g. http://example.com ), but at the same time they don't want the whole mess of WordPress files in the main /root/ directory. WordPress allows you to install it in a subdirectory, but have the site load from your main web address. When you initially install WordPress you have the option to set it to install in the main /server directory of the hosting or in its own subdirectory, but you can change this later if you choose. This may be dictated by a variety of considerations, for example you already have a website installed in the main directory but wish to migrate to WordPress whilst wanting to maintain your Google search rank. In this case, it is a good idea to install WordPress in a subdirectory, with the address that will load for example being http://example.com/име-на-поддиректория/ and later redirect it to the main web address http://example.com/, while also redirecting the old site to the new one. Or you may just have several sites uploaded to the hosting account/server and want each to be in a separate folder for clarity. But let's not get carried away. How can we move/redirect a WordPress site from the main directory to a subdirectory and vice versa? That's what we'll cover in the next few lines.

  1. Moving from Root to your own directory

First we create the new directory where we will move the main WordPress files (I will use /WordPress/ in our examples). Then we go into the site's admin panel Settings > General in the WordPress URL: change the address of the place where we have moved the main WordPress files. Example: http://example.com/wordpress

In the field for URL: leave the same URL or if different - the URL of the main directory for example: http://example.com

Moving Wordpress from Root to own directory and back 1

Click Save/Save Changes . (Don't worry about the error message and try to view your blog at this point! You will probably get a message that the files were not found.)

Move your WordPress core files to the new directory you created (WordPress).

Copy the index.php and .htaccess files from the WordPress directory to the main directory of your website (blog). If the .htaccess file is invisible, you may need to set your FTP client to display the hidden files. If you don't use Permalinks friendly, you can do without the .htaccess file. If you are running WordPress on a (IIS) Windows server and using Friendly Permalinks, you will have a web.config instead of a .htaccess file in the WordPress root directory. For the index.php file the instructions remain the same, copy the index.php file to the root directory. However, the web.config file should be treated differently than the .htaccess file - it should be moved to the main directory..

Open the index.php file from the main directory with your favorite text editor and make the following changes in the order you see below:

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

add the name of the directory you moved the main WordPress files to:

require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );

Moving Wordpress from Root to own directory and back 2

Now the login to the admin panel of your site will be at http://example.com/wordpress/wp-admin/ as example.com is your domain name.

If you have set up Permalinks , go to the Permalinks panel and update the permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate permissions for the files. If WordPress cannot automatically overwrite them in the .htaccess file, it will show you the new rules and you will have to manually overwrite them in your .htaccess file (in the root directory where you copied the index.php file).

  1. When you have installed the site from scratch in a subdirectory, but want to redirect it to the main web address - http://example.com.

If you already have WordPress installed in its own directory (for example, http://example.com/wordpress ), the steps are similar to the above case:

From the administration panel of the site Settings > General > in the field for WordPress URL: the address remains the same. Example: http://example.com/wordpress

In the field for URL: enter the URL of the root directory for example: http://example.com

Moving Wordpress from Root to own directory and back 3

Click Save/Save Changes . (Don't worry about the error message and try to view your blog at this point! You will probably get a message that the files were not found.)

Copy the index.php and .htaccess files from the WordPress directory to your site's root directory (blog address). The login to the site admin panel remains the same http://example.com/wordpress/wp-admin/

Open the index.php file from the main directory with your favorite text editor and make the following changes in the order you see below:

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

add the name of the directory you moved the main WordPress files to:

require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );

Moving Wordpress from Root to own directory and back 4

If you have set up Permalinks , go to the Permalinks panel and update the permalink structure. WordPress will automatically update your .htaccess file if it has the appropriate permissions for the files. If WordPress cannot automatically overwrite them in the .htaccess file, it will show you the new rules and you will have to manually overwrite them in your .htaccess file (in the root directory where you copied the index.php file).

Voila! Your site now loads from your main web address, for example http://example.com

If you have built internal links on your site, you will need to manually revise them after all these actions.

Keep in mind that with some of these actions your site won't be visible to users so it's nice to perform in low activity conditions, for example, in the middle of the night.

The following links explain in detail how to change specific directories within WordPress:

Source: WordPress Codex

Call us!

We look forward to discussing your upcoming web projects.