How can I make WordPress redirect all requests to subdomain.domain1.com to www.domain2.com

As the question says really, How can I make WordPress redirect all requests to subdomain.domain1.com to www.domain2.com.

I have a wordpress site on windows azure – I’ve added the below to the htaccess file but nothing seems to be happening:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(.*)subdomain.domain1.com/$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]

Related posts

Leave a Reply

1 comment

  1. Change your rule to:

    RewriteCond %{HTTP_HOST} ^subdomain.domain1.com$ [NC]
    RewriteRule ^ http://www.domain2.com%{REQUEST_URI} [R=301,L]
    
    1. Make sure to place this rule on top of all other rules in your .htaccess.
    2. Make sure to reflect same domain change in WP permalink settings

    The following is the comments summarised into the answer:

    For wordpress sites hosted on on azure (and therefore in IIS) you dont use the htaccess file for rewrites, you actually need to add a web.config as described here http://www.davebost.com/2013/07/11/moving-a-wordpress-blog-to-windows-azure-part-5-moving-from-a-subfolder-to-the-root

    The following rewrite rule would achieve the required result:

    ...
    <rule name="Redirects to www.domain2.com" patternSyntax="ECMAScript" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAny">
            <add input="{HTTP_HOST}" pattern="^subdomain.domain1.net$" />
        </conditions>
        <action type="Redirect" url="http://www.domain2.com/{R:0}" />
    </rule>
    ...