Monday, March 30, 2009

Empty Folder Creation with Wordpress as CMS

Another experience I thought I should document to be helpful to others... this time it's about the wordpress installation on

A while back we decided to move away from a proprietary Ruby on Rails application for and opted for a Wordpress CMS + Pictage web presence. ProPhotoBlogs provided the awesome CMS + Template and Pictage provided the commerce and client interaction. Great solution for a photography who has a brother who doesn't have enough time to work on said ROR app anymore :)

Since Wordpress was going to act as a CMS as opposed to just a blog as before, we decided to give wordpress it's own directory as to not clutter up the root dir (as if it weren't already) and so the URLs for the various Wordpress Pages wouldn't all be /blog/page_title (higher level directory and more relevant semantics = more SEO friendly). So we moved wordpress from /blog to /wordpress, brought index.php out into the root and modified it to use /wordpress for dependencies. Simple enough, right? Well... not quite.

Since the blog had already been in use for sometime, there were countless references in the db to /blog, including uploaded images for post content. So, we dumped the db through phpMyAdmin (4.8mb mind you!) fired up TextMate, searched and replaced all instances of /blog/ with /wordpress/, and updated the db.

At this point there shouldn't have been anymore problems due to the move... like I said, there shouldn't have been anymore problems. Of course, there were.

Every once in a while a folder named "blog" would show up in the root directory. Normally, this would just be an oddity but in this case it was interfering with a permalink we had setup for a Wordpress Page rendered the actual blog. If a directory with the name of the permalink for a Wordpress Page is present in the site root, the directory gets precedence. In this case, the directory was empty, so when a user visited they'd see an apache generated directory listing of *nothing*. Not good for those subscribed to blog!

Further investigation revealed that the folder was being created every morning around 5:30am. There were no existing cron jobs that were creating this folder, there were no references to it in the db, yet there it was, every morning around 5:30am. Very strange.

I still have not determined what is causing this folder to be created. My only guess is that there is some configuration file used by one of the plugins (or possibly Wordpress itself) that is referencing that directory and creates the folder when it hits a "!exists" statement. Argh, still bugs me.

I didn't have time it trace the problem any further, so instead I turned lemons into lemonade...

Wordpress uses clever (and simple) .htaccess files to direct URI requests to permalinked pages (Rails does the same thing). So, I just put a modified .htaccess file in the suborn /blog directory which made the browser redirect to the correct permalinked location:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . . /index.php [L]

The RewriteRule . . /index.php [L] is the important bit that routes the URI request to the index.php in the root folder. Case closed... sort of.

1 comment:

Chris said...

I had really hoped that would work for me! Sadly, it didn't.

If only I could work out what was creating the folder!