Resolving Redirect Issues After Cloning a WordPress Website
When using FlashPanel's Clone Website feature, users often ask:
"Why does the cloned site redirect to the original website?"
For example:
- example.com (clone version)
- test.example.com (original version)
This guide explains the reason for the redirection and how to resolve it.
Why Does This Happen?
When FlashPanel clones a website, it performs a full copy of:
- The source code (website files)
- The database
FlashPanel does not make any changes to the website's content, database, or configuration during cloning.
For WordPress websites, redirection occurs because WordPress stores the site URL and home URL in its database. If these
values still reference the original domain (e.g., test.example.com), any requests to the new domain (e.g., example.com)
will be redirected back to the original domain.
How FlashPanel Handles This
FlashPanel uses WP-CLI to automatically update the WordPress siteurl and home options in the database to match the new
domain during the cloning process.
However, if your wp-config.php file contains hardcoded values for WP_HOME or WP_SITEURL, the redirection issue will
persist.
How to Fix the Issue
Step 1: Check for Hardcoded Values in wp-config.php
1. Access your WordPress website's files using a file manager or SSH.
2. Open the wp-config.php file in the root directory of your WordPress installation.
3. Look for the following lines:
define('WP_HOME', 'http://test.example.com');
define('WP_SITEURL', 'http://test.example.com');
Step 2: Update or Remove the Hardcoded Values
- Option 1: Remove the lines
If you remove these lines, WordPress will use the values stored in the database.
// Remove these lines from wp-config.php
// define('WP_HOME', 'http://test.example.com');
// define('WP_SITEURL', 'http://test.example.com');
- Option 2: Update the values
Replace the old domain with the new domain (e.g., http://example.com).
define('WP_HOME', 'http://example.com');
define('WP_SITEURL', 'http://example.com');
Step 3: Restart PHP Opcache (If Enabled)
If your server has Opcache enabled, changes in wp-config.php might not take effect immediately.
1. Go to the Server Management page in FlashPanel.
2. Select the Apps tab.
3. Locate the version of PHP your website is using (e.g., PHP 8.3).
4. On the right-hand side, click the Restart button.
This will clear the Opcache and apply the changes made in wp-config.php.
Step 4: Test the New Website
1. Save the changes to wp-config.php.
2. Visit the new cloned domain (e.g., example.com) to ensure it no longer redirects to the original domain.
Tips for Avoiding Issues
- Always ensure the WordPress database is updated with the correct siteurl and home values.
- Use the FlashPanel WP-CLI integration for automatic updates during cloning.
- Avoid hardcoding WP_HOME and WP_SITEURL in wp-config.php unless absolutely necessary.
- Remember to restart the PHP Opcache after making changes to configuration files.
By following these steps, you can ensure that your cloned website functions correctly without redirecting to the
original domain.