WordPress mod_rewrite redirect specific folders

Posted by Ps Cjef on Pro Webmasters See other posts from Pro Webmasters or by Ps Cjef
Published on 2012-05-30T16:37:48Z Indexed on 2012/05/30 17:00 UTC
Read the original article Hit count: 231

As a new user, I'm not allowed to post more than two hyperlinks here. So I have added a space after every http (ignore them and read as full URLs).

System: Debian Etch, Apache 2.2

I have a WordPress instance with multiple blogs. I would like to redirect some of the folders based on the year and month, while leaving other folders go to the actual locations.

Example: I have archives for a few years, like 2010, 2011 and 2012:
http ://mydomain.com/wordpress/myblog/2010/02
http ://mydomain.com/wordpress/myblog/2011/01
http ://mydomain.com/wordpress/myblog/2012/01

I would like to redirect all 2010 and 2011 posts to another blog with the same folder structure:
http ://mydomain.com/wordpress/myotherblog/2010/02
http ://mydomain.com/wordpress/myotherblog/2011/01
and so on.

I would like to have 2012 and beyond to go to the actual site (http ://mydomain.com/wordpress/myblog/2012/01).

I tried mod_rewrite with the following, one rule at a time to test redirection for just one year (and to expand later for other years), and none of them worked!
* RewriteEngine is already on since there are some default WordPress rewrites.
* RewriteBase is set to http://mydomain.com/wordpress/ .
* I put my rule before all the other default WordPress rules are processed.

Didn't work solution #1

RedirectMatch 301 /myblog/2010/(.*) /myotherblog/2010/$1

Didn't work solution #2

RewriteRule /myblog/2010/(.*) http ://mydomain.com/myotherblog/2010/$1 [R=301]

Didn't work solution #3

RedirectPermanent /myblog/2010/(.*) http ://mydomain.com/myotherblog/2010/$1

I've also tried the above rules with and without a fully qualified URL for the new location.

The rewrite log, with log level set to 9, did not provide any useful information. It shows that it looks at the pattern specified against the URL (as mentioned in the rule), but finally what happens is a passthrough to http ://mydomain.com/myblog/ for all URLs or a 500 Internal Server Error.

Any ideas on where I could be going wrong or any alternative solutions?

© Pro Webmasters or respective owner

Related posts about apache

Related posts about Wordpress