this is what I did and expect to clone a wp blog for development.
but the problem is the sub domain keep redirecting to the main domain
To create you should
export DB
change the URLs in db file
open db file using Wordpad or any editor
find wp_options
then scroll down little bit, you find your old URL
replace the old URL to new URL in complete file
save the file.
import the file to the new DB
now run the new URL in browser
Note: after this you must add the widget data and also update the permalinks
simply add this to your wp-config file
define('WP_HOME','http://subdomain.example.com');
define('WP_SITEURL','http://subdomain.example.com');
You need to update the site URL and home URL in your database (wp_options
table). You'll probably want to replace other mentions of your old URL too, such as in linked posts or the guid
.
You say you use cPanel, so you should have access to phpMyAdmin. If you go there, you can run this SQL (you'll need to replace the old and new URLs where appropriate):
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');
I think you have to change the siteurl entry inside of the wp_options table. Search for siteurl by field option_name.
This might have been answered in a newer post/Q, but FWIW: In addition to the proposed solution (the change of URLs inside the wp_options table), I need to modify the .htaccess file as well like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir[L]
Here's the WP support site where I found the code and further info: https://wordpress.org/support/article/giving-wordpress-its-own-directory/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With