My Sub Domains redirect to Main Domain after site copy

Hi there! We recently copied an existing Multisite to a new domain for testing/sandbox purposes and it’s almost working, but we are having one major issue. The sub domains index files are redirecting to the main domain and I can not determine why. If you go to a specific page on the sub domain it works fine, but when you go to the home page of the sub domain blog it’s redirecting…

For example: redirects to

but works perfectly

Has anyone experienced this before? The confusing part is that all the fines are coming from an existing multisite install that is working perfectly. As far as I can tell, all the Database entries have been updated to reflect the new domain, but I’m stumped.

Any help would be so very appreciated.

We are using virtually all the WPMU plugins, so if you know of any plug in that could be effecting that, please let me know.

Really appreciate your help in advance!

  • skishopmatt
    • Site Builder, Child of Zeus

    Hi Jack! Thanks for taking a look at this, I’m going bald pulling my hair out :slight_smile:

    Here’s the .htaccess file:

    RewriteEngine On
    RewriteBase /

    #uploaded files
    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
    RewriteRule ^(.*/)?files/(.*) wp-includes/ms-files.php?file=$2 [L]
    RewriteRule ^(.*/)?avatar/(.*) wp-content/avatar.php?file=$2 [L]
    RewriteRule ^(.*/)?sitemap.xml wp-content/sitemap.php [L]

    # add a trailing slash to /wp-admin
    RewriteCond %{REQUEST_URI} ^.*/wp-admin$
    RewriteRule ^(.+)$ $1/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
    RewriteRule . index.php [L]

    #AddHandler application/x-httpd-php5 .php

    <IfModule mod_security.c>
    <Files async-upload.php>
    SecFilterEngine Off
    SecFilterScanPOST Off

    <Files 403.shtml>
    order allow,deny
    allow from all

    deny from
    deny from
    deny from
    deny from

    and wp-config

    * The base configurations of the WordPress.
    * This file has the following configurations: MySQL settings, Table Prefix,
    * Secret Keys, WordPress Language, and ABSPATH. You can find more information
    * by visiting {@link Editing
    * wp-config.php} Codex page. You can get the MySQL settings from your web host.
    * This file is used by the wp-config.php creation script during the
    * installation. You don't have to use the web site, you can just copy this file
    * to "wp-config.php" and fill in the values.
    * @package WordPress

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'XXXX');

    /** MySQL database username */
    define('DB_USER', 'XXXX');

    /** MySQL database password */
    define('DB_PASSWORD', 'XXXX');

    /** MySQL hostname */
    define('DB_HOST', 'localhost');

    /** Database Charset to use in creating database tables. */
    define('DB_CHARSET', 'utf8');

    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');

    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    //define('VHOST', 'yes');
    $base = '/';
    define('DOMAIN_CURRENT_SITE', '');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOGID_CURRENT_SITE', '1');
    define('SUNRISE', 'on');
    define('NOBLOGREDIRECT', '');

    //** turn on SEO settings for blogs, remove to enable editing of SEO settings */
    define('WDS_SITEWIDE', false);

    * Authentication Unique Keys and Salts.
    * Change these to different unique phrases!
    * You can generate these using the {@link secret-key service}
    * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
    * @since 2.6.0
    define('AUTH_KEY', 'xxx;
    define('SECURE_AUTH_KEY', 'xxx;
    define('LOGGED_IN_KEY', 'xxx;
    define('NONCE_KEY', 'xxx;
    define('AUTH_SALT', 'xxx;
    define('LOGGED_IN_SALT', 'xxx;
    define('NONCE_SALT', 'xxx;

    * WordPress Database Table prefix.
    * You can have multiple installations in one database if you give each a unique
    * prefix. Only numbers, letters, and underscores please!
    $table_prefix = '';

    * WordPress Localized Language, defaults to English.
    * Change this to localize WordPress. A corresponding MO file for the chosen
    * language must be installed to wp-content/languages. For example, install
    * to wp-content/languages and set WPLANG to 'de' to enable German
    * language support.
    define ('WPLANG', '');

    * For developers: WordPress debugging mode.
    * Change this to true to enable the display of notices during development.
    * It is strongly recommended that plugin and theme developers use WP_DEBUG
    * in their development environments.
    define('WP_DEBUG', false);

    define('WP_ALLOW_MULTISITE', true);

    /* That's all, stop editing! Happy blogging. */

    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

    /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-settings.php');

    Any specific suggestions as to which tables to look in in the database?

    Here’s some live URLS as well:


    Sub Domain Fail Example:

    Sub Domain Page Success:

    Thanks agin for taking a look at this, I hope we can figure something out together!


  • Jack Kitterhing
    • Code Norris

    Hi there Matt,

    I hope you are well today, sorry for the delay on this, I missed your previous response.

    I believe that the .htaccess is causing the issue here, could you deactivate all plugins and in the .htaccess file replace all your current rules with this set of rules (Only if your multisite was installed on 3.5 and up)

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^(.*.php)$ wp/$1 [L]
    RewriteRule . index.php [L]

    Or if it was installed prior to the release of 3.5 use the following rules instead.

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]

    # uploaded files
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]
    # END WordPress

    Thank you!

    Kind Regards


  • skishopmatt
    • Site Builder, Child of Zeus

    Thanks Jack!

    I haven’t tested yet, but I wanted to clarify, when you say “installed prior to release of 3.5” do you mean if the Multisite was installed before that? Or do you mean if currently have 3.5 installed? Just want to make sure I’m using the right thing.

    Our MS was installed with 3.0 I believe, maybe 3.1, but we are currently running 3.5.1

    Let me know which version you’d suggest.

    Thanks so much

  • skishopmatt
    • Site Builder, Child of Zeus

    As an update, I’ve deactivated all network activated plug ins (32 of them) and tried both versions of the htaccess to no avail. still redirecting to the main site…

    Do I need to deactivate all the additional plug ins as well? Referring to Drop In’s and Must Use.

    If so, do I do that by renaming them? Not sure how to deactivate them.

    Let me know.

    Thanks again in advance for your help!

  • skishopmatt
    • Site Builder, Child of Zeus

    OK, another update. I think I may have found something.

    I moved all mu-plugins and that didn’t help. Those have been put back.

    I took the current Sunrise.php file we have and replaced it with the old one and suddenly things seem to be working again.

    This is the version of sunrise.php that I was using:


    if ( defined( 'COOKIE_DOMAIN' ) )
    die( 'The constant "COOKIE_DOMAIN" is defined (probably in wp-config.php). Please remove or comment out that define() line.' );

    // Compatibility mode
    define('DM_COMPATIBILITY', 'yes');

    // domain mapping plugin to handle VHOST and non VHOST installation
    global $wpdb;

    // No if statement needed as the code was the same for both VHOST and non VHOST installations
    if(defined('DM_COMPATIBILITY')) {
    $wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
    } else {
    $wpdb->dmtable = $wpdb->base_prefix . 'domain_map';


    $using_domain = $wpdb->escape( preg_replace( "/^www./", "", $_SERVER[ 'HTTP_HOST' ] ) );

    $mapped_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->dmtable} WHERE domain = '{$using_domain}' LIMIT 1 /* domain mapping */" );

    $wpdb->suppress_errors( false );

    if ( !$mapped_id && ( preg_replace( "/^www./", "", DOMAIN_CURRENT_SITE ) !== $using_domain ) ) {
    $md_domains = unserialize( $wpdb->get_var( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = 'md_domains' AND site_id = 1" ) );

    if( $_SERVER['REQUEST_URI'] == '/' ) {
    foreach ( $md_domains as $domain ) {

    if( $_SERVER['HTTP_HOST'] += strtolower( $domain['domain_name'] ) ) {
    $location = 'http://' . DOMAIN_CURRENT_SITE;

    if ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) == true || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) == true ) {
    header( "Refresh: 0;url=$location ");
    } else {
    if ( php_sapi_name() != 'cgi-fcgi' )
    status_header($status); // This causes problems on IIS and some FastCGI setups
    header( "Location: $location", true, 301 );



    foreach( $md_domains as $domain ) {
    if ( preg_match( '|' . strtolower( $domain['domain_name'] ) . '$|', $using_domain ) ) {
    define( 'COOKIE_DOMAIN', '.' . strtolower( $domain['domain_name'] ) );

    if( $mapped_id ) {
    $current_blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d LIMIT 1 /* domain mapping */", $mapped_id ) );
    $current_blog->domain = $_SERVER[ 'HTTP_HOST' ];

    $blog_id = $mapped_id;
    $site_id = $current_blog->site_id;

    define( 'COOKIE_DOMAIN', $_SERVER[ 'HTTP_HOST' ] );

    $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d /* domain mapping */", $current_blog->site_id ) );

    $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s /* domain mapping */", $current_site->domain, $current_site->path ) );

    $current_blog->path = $current_site->path;

    define( 'DOMAIN_MAPPING', 1 );

    // Added for belt and braces
    if ( !defined('WP_CONTENT_URL') ) {
    $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
    define( 'WP_CONTENT_URL', $protocol . $current_blog->domain . $current_blog->path . 'wp-content'); // full url - WP_CONTENT_DIR is defined further up


    Is there a newer version at this point?

    Making progress!!!!

  • skishopmatt
    • Site Builder, Child of Zeus

    OK – Hopefully the final update :slight_smile:

    I updated the two domain plugin’s (mutli domain and domain mapping) and added the new sunrise.php (from dm_sunrise) and everything seems to be working!

    SO glad this is resolved. I’ll still need to test the domain mapping and multi domains, but at least I can see the sub blog home pages now!

    Yee Haw!

    Thanks again for all of your help!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.