Moving WordPress from a subfolder to the root directory of your website can be a bit complex, but it’s a straightforward process if you follow these steps:
Step 1: Backup your site
Before making any changes, it’s essential to backup your website. This will ensure that you have a copy of your site’s files and database in case something goes wrong during the migration process.
Step 2: Change the WordPress address
In the wp-config.php
file, update the WP_HOME
and WP_SITEURL
constants to point to the new root directory. You can do this by adding the following lines at the top of the file:
define('WP_HOME', 'http://example.com');
define('WP_SITEURL', 'http://example.com');
Replace http://example.com
with your website’s root URL.
Step 3: Update the database
You’ll need to update the database to reflect the new root directory. You can do this by running the following SQL query:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.example.com/subfolder/', 'http://www.example.com/') WHERE option_name = 'home' OR option_name = 'site_url';
Replace http://www.example.com/subfolder/
with your current site URL and http://www.example.com/
with your new root URL.
Step 4: Update theme files
You’ll need to update any theme files that contain hard-coded URLs pointing to the subfolder. You can use a find-and-replace tool or manually search for these instances.
Step 5: Move files
Move all files from the subfolder to the root directory. Make sure to preserve the directory structure and file names.
Step 6: Update .htaccess file
Update the .htaccess
file to point to the new root directory. You can do this by adding the following lines:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/subfolder [NC]
RewriteRule ^(.*)$ /subfolder/$1 [L]
This will redirect any requests from the old subfolder URL to the new root URL.
Step 7: Test your site
After moving your site, test it thoroughly to ensure everything is working as expected. Check that all pages, posts, and images are displaying correctly.
Additional tips
- Make sure to update any plugins or themes that rely on hard-coded URLs.
- If you’re using a caching plugin, clear the cache after moving your site.
- Consider updating your DNS settings if you’re changing your domain name.
By following these steps, you should be able to successfully move your WordPress site from a subfolder to the root directory. If you encounter any issues or have further questions, feel free to ask!
About the author