Traffic sign of 301 htaccess redirectWhen you use domain mapping on a Multisite install (or anything similar, I know Drupal has this too), you run into the issue of sometimes wanting to redirect a URL just for one domain.

Over the 15 years I’ve had this site, I’ve moved my blog posts around from to back to and then to and finally to And in those years, I’ve managed to never slaughter my SEO. Why? Becuase I know the secret magic of .htaccess. I don’t (yet) use nginx, I’m sure that will change one day, so right now my genius is limited to knowing how to do a nice regex redirect in .htaccess.

The majority of this magic comes in two lines:

RewriteRule ^blog/([0-9]{4})/([0-9]{2})/(.*)$$1/$3 [L,R=301]
RewriteRule ^blog/(.*)$$1 [L,R=301]

I also have this to handle the

RewriteCond %{HTTP_HOST} ^blog\.ipstenu\.org  [NC]
RewriteRule ^(.*)$1 [L,R=301]

The RewriteCond is the neat bit that says ‘If you come here from, use the following rule.’ The [NC] is because domains aren’t case sensitive, and we want to CYA.

For my old setup of a single install, this was great. Today I’m using Multisite, and if I used that redirect, then any site on my network would be redirected! If you’re using subfolder Multisite, you don’t need to worry about this at all, since a redirect for ^blog/ will only impact a URL that has the first folder of /blog/. And that’s precisely why it’s a problem for Subdomains and mapped domains (of which I use both). That redirect up there would affect both and and — and I don’t want any of that. I only want to redirect for those URLs if you’re going to

Thankfully, if you look at what I did for redirecting, you can easily see how to leverage that for this into two checks:

RewriteCond %{HTTP_HOST} ^ipstenu\.org  [NC]
RewriteRule ^blog/([0-9]{4})/([0-9]{2})/(.*)$$1/$3 [L,R=301]
RewriteCond %{HTTP_HOST} ^ipstenu\.org  [NC]
RewriteRule ^blog/(.*)$$1 [L,R=301]

Why did I duplicate the RewriteCond? Typically, you cannot use multiple RewriteRule statements following a single RewriteCond. That means for ever call I make to a domain, I can use but one rewrite rule. There are ways around that, but none of them worked well for me.

If you look at, however, the world gets even messier. Half-Elf is the combination of three domains. Ouch. Two can point to the same place, one needs to redirect totally differently, and then I have a category merge. Oddly that came out as only three sets.

First we can look for and and redirect everything to The trick to this is using (code|tech) in my RewriteCond, which really is one of my favorite things. That’s a built in ‘or’ right there, and if I had a hundred subdomains, I could still do that.

RewriteCond %{HTTP_HOST} ^(code|tech)\.ipstenu\.org [NC]
RewriteRule ^(.*)$1 [L,R=301]

Next we want to redirect to – notice how I don’t want to redirect it like I did for code and tech. Here, everything gets dumped back to the ebook page:

RewriteCond %{HTTP_HOST} ^ebooks\.ipstenu\.org [NC]
RewriteRule ^(.*) [L,R=301]

Finally I want to tackle the merge of my old categories, and again this is straightforward:

RewriteCond %{HTTP_HOST} ^halfelf\.org [NC]
RewriteRule ^category/code/(wordpress|bbpress|buddypress)(.*)?$ [L,R=301]

My actual .htaccess is even crazier, since I have four domains pointing to multisite plus an add-on for my short URLs.

This should get you started on customizing redirects in .htaccess for multiple domains. What are you favorite tricks?

Reader Interactions

%d bloggers like this: