Wednesday 02 November 2005 by sencer

Ok, so here is a somewhat experimental feature (only 4.0.2 and up) for which I am interested in getting some feedback from users that are willing to try it out for a while. This may have some side-effects, so it may not be the best thing to use on a client’s site. And in the unlikely case that this experimental feature clashes with other things, it may be possible that it is dropped in a future update. Also make sure that you have you tried all of the suggestions in clean urls on different hosts.

So, having that disclaimer out of the way, let’s roll. How does it work? Basically it’s an old idea that came up a few times: Use the 404-Handling of the webserver to redirect to textpattern’s index.php. This is how clean urls are achieved for lighttpd (without any problems), and it is basically the same (semantically) that our rewrite-rules try to achieve. But for some reason Apache has this “problem” (or feature) that you loose all POST data when you re-direct via ErrorDocument, which means that comments (and potentially some other features) don’t work. So the user strawberryfusion on the forum suggested that basically the only thing needed to get comments working, was to pass them through messy urls, and use clean urls for the rest.

So here’s how you do it:

Step 1: Your .htaccess file, comment out all mod_rewrite related lines (throw a # sign in front of them), and add the following line to it:
ErrorDocument 404 /weblog/index.php
Note that I used weblog in that url, which assumes you have textpattern installed into a subdirectory called weblog, if it’s installed in the webroot, you would use ErrorDocument 404 /index.php and so forth.

Step 2: Edit your config.php and add the following
define('PARTLY_MESSY',true);
(brilliant naming, eh?). Make sure you add this within the php-delimiters, meaning it should be sitting right next to (below, above or between) the $txpcfg-lines that are there.

Step 3: Now you can go into Textpattern’s preferences and choose one of the clean url schemas and enjoy.

Note: After clicking preview on comments, you will have a messy url during commenting, but are redirected to clean urls when you cancel, submit or click elsewhere. Due to the messy url necessary during previewing/commenting, you are somewhat more limited in how far you can customize comments (only on individual article pages), but I’ve hardly seen any people doing it otherwise anyway. It’s also possible that plugins exist (which create forms of type POST on the public-side) which would not work with this way of achieving clean urls. But other than that I don’t know if it has any drawbacks, that’s why I’m interested in getting some feedback from long-term usage by the brave souls desperate enough to try this out… ;)