case-specific mod rewrite on Wordpress subdomain multisite

Posted by Steve on Pro Webmasters See other posts from Pro Webmasters or by Steve
Published on 2011-10-03T11:40:30Z Indexed on 2011/11/14 18:13 UTC
Read the original article Hit count: 349

Filed under:
|

I have split a Wordpress blog into multiple category-specific blogs using subdomains, as the topics in the original blog were too broad to be lumped together effectively.

Posts were exported from the parent www blog and imported into the subject-specific subdomain blogs.

I believe .htaccess provides mod rewrite for all subdomains (including the original www) in a single .htaccess file.

I use .htaccess to perform 301 redirect on post categories to the relevant post on the subdomain's blog. eg:

RedirectMatch 301 ^/auto/(.*)$ http://auto.example.com/$1

The problem I have is that the category has been retained in the permalink structure in the subdomain blog, so that www.example.com/auto/mercedes is now auto.example.com/auto/mercedes.

The 1st URL is redirect to the 2nd, but unfortunately, the 2nd URL is redirected to auto.example.com/mercedes using the same rewrite rule, which is not found, as the permalink on the subdomain's blog retains the parent category of auto.

The solution would be to adjust the permalink structure in the subdomain's WP settings, so that the top level category does not duplicate the subdomain.

My question would be: how do I then strip a section of the original (www) blog's post URL from the subdomain's URL when redirecting? eg: How do I redirect www.example.com/auto/mercedes to auto.example.com/mercedes?

I'm assuming this would be a regular expression trick, which I am not great at.

Update: I might have to use:

RewriteCond %{HTTP_HOST} !auto.example.com$

in the default Wordpress if loop in .htaccess, and seperate my custom subdomain redirections into a second if loop section.

© Pro Webmasters or respective owner

Related posts about mod-rewrite

Related posts about subdomain