.htaccess redirect from subdomain to subdomain

A new client needs my help, their web developer messed up – built website on a draft/test server but forgot to block Google etc. I would appreciate help for the community here, I am not an expert with HTACCESS redirection.

As I said, another website developer setup the clients draft site on their draft server, its been there for months, however they forgot to hide it from search engines, so the content has been indexed by Google etc – this will trigger a duplicate content penalty if web put the new website live and the new website will be useless effectively.

Read More

I have access to the draft site / server and can modify the HTACCESS file, so when the new site goes live I would like to have the correct redirects in place. There are a few subdomains on the site (it’s a multi language site), so it’s a little tricky.

The website is built on WordPress

The website structure looks like this on the test server. All files page names and file names are identical, just moving to a new server.

http://clientdomain.testserver.com
http://it.clientdomain.testserver.com
http://fr.clientdomain.testserver.com
http://es.clientdomain.testserver.com
http://de.clientdomain.testserver.com
http://ko.clientdomain.testserver.com
http://pt.clientdomain.testserver.com
http://ru.clientdomain.testserver.com
http://tr.clientdomain.testserver.com
http://cn.clientdomain.testserver.com

The redirects will need to go here:

http://clientdomain.com
http://it.clientdomain.com
http://fr.clientdomain.com
http://es.clientdomain.com
http://de.clientdomain.com
http://ko.clientdomain.com
http://pt.clientdomain.com
http://ru.clientdomain.com
http://tr.clientdomain.com
http://cn.clientdomain.com

The existing HTACCESS file on the test server looks like this

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)$ $1 [L]
RewriteRule . index.php [L]

I would really appreciate any help on this.

There are some existing threads which contain all the pieces of the HTACCESS puzzle, but I am a little confused:

How can I redirect from one subdomain to another in .htaccess?
How can I redirect from one subdomain to another in .htaccess?

Kind Regards,
GG

Related posts

Leave a Reply

2 comments

  1. If it was me I wouldn’t bother messing around with redirects, get the urls removed from the index. Google will remove them with 24 hours, sometimes much quicker nowadays.

    Add the development domain to your Webmaster Tools account and verify it. Then go to Google Index -> Remove Urls;

    enter image description here

    Just enter the the value / in the removal request which tells Google to remove every url in the index for that domain.

    enter image description here

    Then add a blocking robots.txt file to site root;

    User-agent: *
    Disallow: /
    

    And what I normally do (this has happened a couple of times to me despite robots.txt and basic auth protection – git disaster/shenanigans) is prompt Google to reindex the site straight away. Go to Crawl -> Fetch as Google

    enter image description here

    Leave the input box blank so it fetches the whole site and just hit the Fetch button. When Google has fetched it click the ‘Submit to Index’ button.

    enter image description here

    You will be amazed how quickly this can happen these days, used to take weeks if you were lucky.

    EDIT

    And just to make sure this doesn’t happen to anyone else finding this, the best way to stop it getting a dev site indexed isn’t a robots.txt file or using Basic Auth via the .htaccess file (as previously mentioned it’s easy to accidentally delete these). You should enable Basic Auth on the development site via the vhosts file.

  2. Like it’s not only for Google…
    You can use this .htaccess:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^((?:...)?clientdomain).testserver.com [NC]
    RewriteRule ^ http://%1.com%{REQUEST_URI} [NE,L,R=301]