2

EDITED: I've split a website into two subsites in a multisite enviroment.

The old site was moved to a subsite, and renamed old.mysite.example. This will be faced out at some point.

During development I had a redirect sending all visitors to the old.mysite.example subsite. Now that the work is done I need a very spesific redirect.

I want users that type in old.mysite.example sent back to www.mysite.example Where as I want users clicking on postlinks such as old.mysite.example/an-article-here sent to new.mysite.example/an-article-here.

Now redirect that removed the first mentioned redirect is working. But not the other. Anyone got a good way to do this ?

4
  • Isn't this just a standard domain redirect? Although you've created a new subdomain for the new site, rather than using the same hostname as the original site??
    – MrWhite
    Sep 3, 2019 at 16:40
  • Actually it is a more complex thing than that. It didn't solve the entire issue. But I don't know how to re-open the question. I split the old website into a multisite-solution. So What I actually need is a redirect that will send users who type old.mysite.com to the www.mysite.com where as those who click on postlinks such as old.mysite.com/an-article-here is sent to new.mysite.com/an-article-here.
    – XanderMan
    Sep 5, 2019 at 2:59
  • 1
    @XanderMan Please edit the question to include the .htaccess code that you've tried or having partially working. Thanks.
    – dan
    Sep 5, 2019 at 3:50
  • So you desire to have any deep link go to a new site and the home page go to a different new site? Sep 5, 2019 at 10:24

1 Answer 1

1

NB: Any redirects that you add to .htaccess need to go before the WordPress front-controller.

I want users that type in old.mysite.example sent back to www.mysite.example

RewriteCond %{HTTP_HOST} ^old\.mysite\.example [NC]
RewriteRule ^$ https://www.mysite.example/ [R=302,L]

The regex ^$ matches an empty URL-path, ie. a request for the document root only.

Where as I want users clicking on postlinks such as old.mysite.example/an-article-here sent to new.mysite.example/an-article-here

This is assuming you have already updated all the internal links on your own site and this is just for the benefit of any external 3rd parties (or search engines) that have linked to old.mysite.example/an-article-here.

Following the above redirect:

RewriteCond %{HTTP_HOST} ^old\.mysite\.example [NC]
RewriteRule (.+) https://new.mysite.example/$1 [R=302,L]

The regex .+ ensures it matches something and not nothing, so as not to conflict with requests for the document root that redirect elsewhere. Although with the directives in this order, it shouldn't really matter.

Change the 302 (temporary) redirect to 301 (permanent) only once you have confirmed the redirects are working OK. This is to avoid erroneous redirects being cached by the browser.

Clear your browser cache before testing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.