Step 1: Update WordPress General Settings
Log in to your WordPress admin dashboard.
Go to Settings > General.
Look for the fields labeled “WordPress Address (URL)” and “Site Address (URL).”
Change the “Site Address (URL)” to your main domain (www.example.com).
Save changes.
This step ensures that WordPress knows its main URL is the root domain.
Step 2: Update .htaccess File
If you are using Apache as your web server, you might need to modify your .htaccess file. In the root directory of your WordPress installation, you should find a file named .htaccess. Open it in a text editor and add the following code:
apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
This code helps with the proper rewriting of URLs. Make sure to replace /blog/ with your actual subdirectory name.
Step 3: Update Permalinks
In your WordPress admin dashboard, go to Settings > Permalinks.
You don’t need to change anything, but click “Save Changes” to refresh your permalink structure.
Step 4: Update wp-config.php
Connect to your website using an FTP client or use your hosting provider’s file manager.
Locate the wp-config.php file in the root of your WordPress installation.
Open wp-config.php in a text editor.
Add the following code near the top of the file, just after the opening <?php tag:
define('WP_HOME', 'https://www.example.com');
define('WP_SITEURL', 'https://www.example.com');
Replace https://www.example.com with your actual domain.
Step 5: Update Database URLs
In some cases, you might need to update URLs stored in your database. You can use a plugin like “Better Search Replace” to search for instances of your subdirectory URL and replace them with your main domain URL.