putting wordpress in subdirectory of site

January 7, 2010

in wordpress

Just a quickie:

I wanted to put this wordpress-driven blog in a subdirectory of the site (i.e., www.mattvsworld.com/blog), but I wanted the root of the site (www.mattvsworld.com) to be the same as the root of the blog (www.mattvsworld.com/blog).  Here’s how I did it (using apache and mod_rewrite):

  1. Created the subdirectory “blog” on the web server, and placed the normal wordpress installation entirely within that fodler.
  2. Ran the installation normally (if you already installed in the root and moved, you can just modify the configuration files to indicate that it’s new location)
  3. Copied the “index.php” file from the “blog” directory to the site root.
  4. Modified the now-root index.php, changing the line:
    require('./wp-blog-header.php');

    to

    require('./blog/wp-blog-header.php');
  5. Since I wanted the wordpress-managed robots.txt file to be available from the normal site root directory (i.e. /robots.txt rather than /blog/robots.txt), I created an .htaccess file in the site root with the following contents:
    <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /
       RewriteRule ^robots.txt$ /blog/robots.txt
    </IfModule>

And now I’m happy — the site root is managed with wordpress, but the blog is nicely nested within a /blog/ subdirectory.  In case I need to change things in the future, my permalinks should stay, well, perma!

Cheers

{ 1 comment… read it below or add one }

Rose Vines April 29, 2010 at 8:23 am

Thanks, Matt. I was wondering how to redirect robots.txt and your little piece of code does the trick.

Cheers,

Rose

Leave a Comment

Previous post:

Next post: