301 Redirects for posts, category, pages from original domain to sub-domain of multisite

You can do the redirection in one step or in two steps. The one step solution redirect all traffic directly to the correct URL on the new server, the two step solution simply redirects all traffic to the same path on the new server, and let the new server figure out the correct path after that. I don’t know whether there is a SEO penalty with two redirects, maybe you should ask this on the related Pro Webmasters Stack Exchange site.

Redirect in two steps

In two steps is probably the easiest to set up: you redirect all traffic to site1.com/some/path to sub1.site2.com/some/path, and let the second site figure out the correct destination, for example with the Redirection plugin.

You can configure the first redirect in Apache, with a simple Redirect rule in your server configuration (.htaccess, or httpd.conf or related):

Redirect 301 / http://sub1.site2.com/

You could also do this in PHP, but for such a simple redirection it would be overkill.

Redirect in one step

If you want to redirect in one step your old server should know the new location of all URLs. For your posts this seems to be easy (only the date is stripped?), but what about the category and archive pages? Anyway, you can also do this in Apache with a RedirectMatch rule and a simple regular expression. Basically you want to match all URLs that start with a year and a month and then some stuff, and redirect them to the new site + some stuff. \d means “a digit”, {4} means “repeated 4 times”, . means “any character”, and + means “repeated one or more times”. The () “collect” the match, so we can use it in the replacement (as $1).

RedirectMatch 301 /\d{4}/\d{2}/(.+) http://sub1.site2.com/posts/$1

You can combine both rules, so posts get redirected in one step and everything else in two steps. The first rule that matches is executed, so place the regex rule on top.

Leave a Comment