How to write an htaccess call to handle an entire mapped domain on WordPress Multisite.
Warning: This post has a pretty high geek factor.
You’ve been warned.
Since Otto (@ottodestruct) fixed the wordpress permalink issue in WordPress 3.3, when I moved christopherprice.com to a different WP install, I decided to eliminate the /%year%/ portion of the permalinks he recommended previously.
Since it is very bad for SEO to have previously ranked pages just disappear and show up at different URLs, I needed to set up a 301 redirect (permanent) instruction for each old URL to each new URL. For example:
http://domain.com/2011/post/ should now redirect all visitors (including Google spiders) to http://domain.com/post/.
Rather than tediously writing a specific set of instructions redirecting each post, I wanted to put one single instruction that would take care of all of them. Since the “formula” is repetitive, this should be possible.
But there is another challenge: Usually, each domain would have it’s own .htaccess file. WPMS, on the other hand, has one single .htaccess file to handle all the rewrites for all the domains mapped to the network.
Starting with Ipstenu’s advice for someone in this wordpress support forum, I came up with the following modification to the main wordpress .htaccess file. Note this should go ABOVE all the other wordpress calls.
#Domain Specific Redirects
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com/2012/(.*)\.(php|html)[NC]
RewriteRule ^(.*).html$ http://domain.com/$1 [R=301,L]
I hope someone is helped by this. If so, please leave a comment, share this post on your fav social network, or click the anonymous green thumb of karmic goodness. Thank you!