[This post it outdated! Please see my WordPress plugin that enables pretty permalinks. This post is for informational purposes only]
OK, so this is mostly for any other users who maybe on Netfirms like me.
For some weird reason, Netfirms does not support “pretty” permalinks in WordPress, despite the fact that they claim to have Apache mod_rewrite enabled (Maybe because AllowOveride isn’t enabled, who knows). That’s why for the last month all of my links have been that crazy, ?p=123 or whatever the heck the post number was. Well, after Netfirms Tech Support was of no help (as usual), I decided to do my own research and hack around a bit. 5 hours later, viola! Pretty permalinks!
So how did I do it? Basically, I tricked WordPress to apply it’s internal mod_rewrite rules as if I was passing path_info (the only permalink structure Netfirms supports), and rewrote the mod_rewrite rules to rewrite all the urls to use path_info (try saying that sentence 5 times fast). And guess what, you can do it too! Just follow these easy steps below! (Obviously, I make no claim this will actually work on your own site, and you will actually be adding a line of code into WordPress, so please know what you are doing. This also means if you update WordPress, you will break this little hack. I’m using this on my own installation of WordPress version 2.0.4).
[For WordPress 2.1, 2.2, follow the Update 2007-01-26 instructions]
- Log into your WordPress admin and choose your log awaited permalink structure.
- WordPress will then hopefully create a .htaccess file for you with some mod_rewrite rules. If not, create a blank .htaccess file at the root of your WordPress installation.
- Copy the following mod_rewrite code below and replace the WordPress generated rules with it. Also, remember to change the RewriteBase to your WordPress directory:
Code (apachelog)
-
RewriteEngine On
-
RewriteBase /
-
RewriteCond %{REQUEST_FILENAME} !-f
-
RewriteCond %{REQUEST_FILENAME} !-d
-
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
-
- Open wp-includes/classes.php and find line 1543 or so. It should read something like:
Code (php)
-
foreach ($rewrite as $match => $query) {
Directly after this, add this small piece of code:
Code (php)-
$match = ‘index.php/’.$match;
-
That’s it! Congratulations, enjoy your new pretty permalinks, you lucky Netfirms dog you!
[UPDATE 2006-11-10] This hack above also works with Wordpress 2.0.5.
[UPDATE 2007-01-26] It looks like those crazy developers over at WordPress changed a bunch of things with the new 2.1 release. The hack still works, just the line numbers have changed.
- Like before, modify your .htaccess file with the new mod_rewrite rules found above. Make sure to set the RewriteBase to the correct settings for your server.
- Lock your .htaccess file down! Before, WordPress didn’t touch your rewrite rules unless you changed it in the administration options section. Now, it seems like it will try to update them even if you aren’t in the options section. So chmod your .htaccess file to 444 or a setting that PHP can’t write to.
- Find the classes.php file and open it in your favorite text editor. You can find it in wp-includes/classes.php.
- Look for line 86 or so. It should look like this:
Code (php)
-
// Look for matches.
-
$request_match = $request;
-
foreach ($rewrite as $match => $query) {
-
- Add this line of PHP directly after:
Code (php)
-
$match = ‘index.php/’.$match;
-
That’s it! Ben reported that he was able to get pretty permalinks working by just adding the mod_rewrite rules above for PHP4. I am using PHP5, and I needed the full hack to get mine to work correctly. But you might want to try just adding the mod_rewrite rules above first and see if that works for you.
[UPDATE 2007-08-14] Since I’ve been too lazy to create a decent plugin for this (or maybe I’ve been too busy :-p), I’ve uploaded a hacked (or patched if you want it to sound nicer) classes.php file from the WordPress 2.2.2 release. You can simply download this, and upload it over your old classes.php file in wp-includes. You’ll still need to follow the .htaccess instructions above, since you’d have to enter in your ReWriteBase anyway. Also, this classes file is only for PHP5. If you’re running PHP4, only follow the .htaccess instructions.
Laure:
20061102 10:42HA! That’s why I use GoDaddy!
Actually, not it’s not. I use GoDaddy because it’s cheaper and because I am too lazy to switch it. And also, I am not a code-monkey, so if there are problems, I just smile and nod and keep on ignoring them.