- March 4th, 2011
- Write comment
This is a limited use-case, but it’s one I’ve just successfully figured out how to deal with. Hope it helps.
I have a WordPress codebase that is shared between three domains. The code executes the same on all three domains — only the domain itself is different. Which, there should be nothing inherently problematic about doing this.
Problem is, when you set up your blog’s settings, WordPress requires that you enter a fully-qualified absolute URL for the blog’s root directory — and that URL is inserted throughout every nook and cranny of the app. For whatever reason, you can’t supply it a domain-less path, even though it seems like this would be a perfectly reasonable thing to expect. (I read one explanation that this would be too problematic for many users.) There are way too many references to this absolute URL to fix by hand, and if it can be avoided, it’s not generally a good idea to go monkeying around in the guts of the app to try to change its behavior. Maintenance becomes a lot more hands-on. Upgrading can easily become a migraine.
So: database hacks to the rescue.
You can actually force WordPress to use a domain-less root path, by altering two settings directly in the database. In the
wp_options table, change the
home values to whatever URL you like. Like, say, the perfectly reasonable
/blog. The only downside is that if you ever try to change anything on the General Settings page from within
wp-admin, WordPress will bark at you and give you a couple of error messages. It’s okay. You can ignore them.
Everything else works just fine.
Update: Apparently, everything else does not work just fine. Setting the URL in the database broke Akismet.
Akismet requires the home value in the database options to be the URL associated with your API key. Unsurprisingly, if it doesn’t have that URL, the service requests will fail.
WordPress is great and all, but like every other off-the-shelf software package, there are times where if you want to customize it and color outside the lines they’ve drawn for you, you end up diving down a frustrating rabbit hole.
I’m sure I’ll port this bad boy over to Django soon enough. Then: sweet, satisfying, complete control.