Moving a WordPress website from one directory to another is a very common task when building websites. Here is a easy step by step guide to moving a site on the same domain.
I was doing it the hard way until I found this guide by Ask WP Girl.
Here are the 11 easy steps to move a WordPress website from one folder to another.
Backup
1. Ensure you have all the backups before you begin
Take backups of both the database and the files, you can do this in cPanel using Jet Pack, see below Jet Pack backups.
If you don’t have Jet Pack then there are plugins you can use such as BackupWP but some are no longer free to use, so it is a good idea to use your host server to download the backups.
2. Have access to phpmyadmin and File Manager
To carry out the move you will need access to the website, phymyadmin and File Manager.
Every host provider has a different control panel, or hosting dashboard, so find where you can access the database, phpmyadmin and gain access to File Manager.
Cache everything and de-activate the cache plugin
Make sure the folder you are moving files to is empty of any files
3. Go to settings in WordPress
In WordPress go to Settings > General and remove the subdirectory or add the subdirectory, depending on where you are moving the website.
If you are moving a development website to live, then I suggest adding a maintenance page on the website before you move it. There are a few things that need to be done before once it is moved and you don’t want the owners to see broken links.
In WordPress go to settings > general and change the url to the new url i.e. remove the sub domain or add the sub domain.
Do this for both WordPress Address and Site Address.
Remove the trailing /
Ensure the url ends with the correct domain i.e. https://website.org or https://website.org/sub
Click Save Changes (this updates the database).
4. Move the files to the new folder
Go to File Manager and move all the files to the folder you want the website to be in i.e. root or subfolder.
Ensure the folder is clear of any files/folders that are not needed.
The best way to move all the files is to select all then drag all the files to the new folder.
5. Login into WordPress using the new url
Now login to WordPress, it should automatically change to the new url, if not type in the new url.
Login as normal.
6. Change permalinks
To refresh everything, change the permalinks to update all the links on the site. If you don’t do this you may find 403 pages on links.
Settings > permalinks
7. Install Velvet Urls
You now need to update all the urls so all the links work with the new url.
8. Manually update urls
Some url’s will not get picked up by Velvet Url plug-in so go through the site and manually change url’s.
Check widgets and go to page source and control F to find any url’s that need changing manually.
9. Test the site
If you do get a blank screen ‘white screen of death’ turn off the .htaccess file but giving it a new name temporarily i.e. .htaccess_temp
Test the site is working correctly.
10. Turn caching back on
Turn your caching plug-in back on and clear the cache.
11. Add code to .htaccess for SEO continuity
If you are replacing and old website with a new one you will not want to lose your SEO ranking from the old website, so you should add a wild card redirect from the old url to the new one.
To do this add the code below to your .htaccess file in File Manager (it could be hidden to so to settings > select show hidden files. Add your domain in the code.
On the RewriteRule line use www or don’t use www according to what you have set in WordPress Settings > General.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com/subdirectory$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com/subdirectory$
RewriteRule (.*)$ http://www.mydomain.com/$1 [R=301,L]
Test it first using 302
It is always best to check redirections are set correctly by using 302 instead of 301 redirect.
Enter the URL make sure it rewrites to the new directory, if you are happy its redirecting correctly change to 301 permanent redirect.
Google does not recognise 302 redirect when maintaining SEO credentials.
Summary - moving a WordPress website
If you are managing or building websites then they are going to have to move them from staging to live effectively so the website does not end up with any technical issues.
This guide is a quick guide to help those moving a site from development in a sub folder to live, maybe replacing the old website.
Always take backups and take your time.