I get questions all the time on how to go about moving a WordPress install from a sub-directory into the main/root folder for you website. In other words, you have installed WordPress in yourdomain.com/blog but want it to be accessible from yourdomain.com. All it takes, is just a couple of short steps.
The first thing you need to know is that there are two different paths you can take when doing this and I am going to explain both of them here. The first option is to tell WordPress to appear at yourdomain.com despite the fact that your WordPress files are in another folder. The second option on the other hand involves moving the files to the proper folder straight away.
What are the differences I hear you ask? Apart from organization, not too much. You will not miss out on any special features either way. Probably the most notable thing is that you will just be accessing your admin panel from the “true” file path URL instead of the “illusionary” one.
Changing the Site URL
If you prefer the quick and very painless method that perhaps gives you a little more organization among your files on the server, this is the one to go with.
NOTE! This will not work if you have WordPress MultiSite enabled!
Step 1 – Changing the URL
Sign into your WordPress admin panel and go to Settings > General. In here you will notice two different address fields (URL). The second of these, the one that reads “Site address (URL)” is the one you want to change.
If you want your site to appear at yourdomain.com, put that in the field and go down to update the settings. It is very important that you do not change the WordPress URL.
Step 2 – Copying files
If you now go over to your site, chances are that you will not see it and that it will present you an error message. Don’t worry about that just yet because we just need to do one more thing.
Log into your FTP account using an FTP client and navigate to your wordpress install folder (e.g. yourdomain.com/wordpress). Copy (do not move) two files from here into your root directory (the new directory): index.php
and .htaccess
.
One more thing before we can enjoy the new website. Open up the index.php
file in a file editor of your choice and find this line:
require('./wp-blog-header.php'); |
Because we have moved this file out of its normal place, this relationship between index.php
and wp-blog-header.php
is not intact and we need to make sure it is.
All you do to fix this is add the name of the folder that you have WordPress in, into this PHP statement. For example, if you have your WordPress install under yourdomain.com/wordpress, change it to the following:
require('./wordpress/wp-blog-header.php'); |
Save the file and make sure to upload and overwrite it in your public_html
, root folder and you will now see your site at yourdomain.com.
Moving All WordPress Files
Now comes the second option that you have and that is to move all of your files from the public_html/blog directory to public_html and will require just a little more than the previous method, with the benefit of not having to edit any files at all.
Step 1 – Update WordPress URL Settings
Before moving the files, let’s make our job a little bit easier. By changing the URL parameters properly before we move, we do not have to go into the database and make the changes there, which we would have to do by moving the files first.
Again, always do this step first.
In your WordPress admin panel, under Settings > General, change both of the address (URL) fields (WordPress address & site address) to your new site URL (e.g. yourdomain.com).
Step 2 – Moving the files
With the URL settings all set (you didn’t forget to do it beforehand did you?), sign into your favorite FTP client and open your root folder (usually www
or public_html
on Linux-based servers).
Find your sub-directory that WordPress resides in currently, for example public_html/wordpress
. In most FTP clients you can simply now drag and drop your files from this sub-directory (public_html/wordpress
) into the root (public_html/
).
After that you can load your site at its new location, yourdomain.com.