So the dilemma rose tonight when James wanted Wordpress installed on his domain that he’s had since the dawn of time.  Awesome I say!  How exciting!  Get the zip, unzip it, set it up and go for it.

Well after fighting with Dreamhost for a little while on setting up new SQL database, I discovered there’s 5+ years worth of junk sitting in his root public html directory.  “K dude, I’m just going to move these to a subdomain files. and you can start using that”.  Well, after posting for 5 years of links around the internet – he didn’t like that idea.

So I had this fantastic idea – install WordPress in a subdirectory and I’m sure we can find some .htaccess rewrite rules to compensate.  Turns out, it doesn’t appear to be a popular topic on the web.

So, after hours of fighting with the world – the hacked solution is below.  It’s dreadfully important that you have some sort of SEO friendly (permalinks) turned on before you start using these rules.

RewriteEngine On
RewriteBase /

RewriteRule ^$ /wordpress/index.php [L]

RewriteRule ^wp-login.php$ wordpress/wp-login.php [L]
RewriteRule ^wp-comments-post.php$ wordpress/wp-comments-post.php [L]
RewriteRule ^wp-register.php$ wordpress/wp-register.php [L]
RewriteRule ^wp-rss2.php$ wordpress/wp-rss2.php [L]
RewriteRule ^wp-atom.php$ wordpress/wp-atom.php [L]
RewriteRule ^wp-pass.php$ wordpress/wp-pass.php [L]
RewriteRule ^wp-rss.php$ wordpress/wp-rss.php [L]
RewriteRule ^wp-commentsrss2.php$ wordpress/wp-commentsrss2.php [L]
RewriteRule ^wp-feed.php$ wordpress/wp-feed.php [L]
RewriteRule ^wp-signup.php$ wordpress/wp-signup.php [L]
RewriteRule ^wp-trackback.php$ wordpress/wp-trackback.php [L]
RewriteRule ^wp-activate.php$ wordpress/wp-activate.php [L]
RewriteRule ^wp-links-opml.php$ wordpress/wp-links-opml.php [L]
RewriteRule ^wp-rdf.php$ wordpress/wp-rdf.php [L]

RewriteRule ^wp-admin/(.*)$ wordpress/wp-admin/$1 [L]
RewriteRule ^wp-content/(.*)$ wordpress/wp-content/$1 [L]
RewriteRule ^wp-includes/(.*)$ wordpress/wp-includes/$1 [L]

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

Anywhere “wordpress” is written, this is your subdomain. I’m sure there’s 92 ways to make this far prettier, and if you know of a blog post or forum topic that talks about doing this in a better way, please by all means do give your feedback.

As far as I know, /wp-login.php is the only file other than index.php that’s ever called – so that is why it has a speical rule just for it.  I do suspect James will run into some pages that may require tweaking – and I’ll update this post when that day comes (if it ever comes).

Edit: So the first issue was that comments go back to the wp-comments.php file, so like wp-login I’ve quickly added it in, and the other files I think may be used.