user3836151
user3836151

Reputation: 231

subdomain of wordpress keep redirecting to main domain

this is what I did and expect to clone a wp blog for development.

  1. I created a sub domain in cpanel, says dev.myblog.com
  2. I download a copy of db and then uploaded to the newly created db.
  3. I changed the wp-config - db name etc..

but the problem is the sub domain keep redirecting to the main domain

Upvotes: 11

Views: 16221

Answers (7)

Shawn Carron
Shawn Carron

Reputation: 21

In order for this to work for me I first added the following to wp-config on the sub-domain:

define('WP_HOME','http://subdomain.example.com');
define('WP_SITEURL','http://subdomain.example.com');

The above still forwarded to the main site so I then opened the sub-domain's DB in phpMyadmin and updated the site URL under wp-options.

Once I did that it was forwarding correctly.

Upvotes: 1

cosmus musango
cosmus musango

Reputation: 11

Change the site URL on the WP_OPTIONS table if it exists on DB if not go to wp-config.php and add below two entries on the file.

define('WP_HOME','http://subdomain.example.com');
define('WP_SITEURL','http://subdomain.example.com');

Upvotes: 1

Shah Rukh
Shah Rukh

Reputation: 3156

To create you should

  1. export DB

  2. change the URLs in db file

    1. open db file using Wordpad or any editor

    2. find wp_options

    3. then scroll down little bit, you find your old URL

    4. replace the old URL to new URL in complete file

    5. save the file.

  3. import the file to the new DB

  4. now run the new URL in browser

Note: after this you must add the widget data and also update the permalinks

Upvotes: 8

AnDrej_B
AnDrej_B

Reputation: 11

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/

Upvotes: 1

Thomas Chirwa
Thomas Chirwa

Reputation: 341

simply add this to your wp-config file

define('WP_HOME','http://subdomain.example.com');
define('WP_SITEURL','http://subdomain.example.com');

Upvotes: 4

realkru79
realkru79

Reputation: 31

I think you have to change the siteurl entry inside of the wp_options table. Search for siteurl by field option_name.

Upvotes: 2

Mike
Mike

Reputation: 8877

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');

Upvotes: 3

Related Questions