0

WordPress MU switching between sub-domain to root directory

wordpress-mu-logoRecently my team had to move a WordPress MU instance from a sub-domain to a root directory model.  Oh, for those who do not understand what I just said, WordPress MU gives administrators the ability to create blogs on the fly for their authors and manage the domain space as either a sub-domain (http://blog_title.domain.com/) or part of the root directory (http://domain.com/blog_title/), read about it here.  After rebuilding the environment and updating DNS with the new domain space, it was time to figure out how to prevent 404 errors from web users who have bookmarked content from the old url structure.  Apache rewrite and regular expressions to the rescue!

Since the only thing that changed is the position of the blog title in the url, you can use Apache rewrite mod to change the url to your liking.  So let’s say your old domain url is:

http://abc.domain.com/posts

and your new domain url is now:

http://domain.com/abc/posts

In your .htaccess file or Apache conf, the following lines will make the above change possible:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/abc$1 [R]

  • The caret, ^, signifies the start of an URL, under the current directory
  • The dollar sign, $, signifies the end of the string to be matched
  • The dot sign, ., signifies what file extension to grab

There is a lot more you can do.  Take a look at the Apache reference to learn more.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *