Making WordPress Permalinks Work

I recently spent quite a while trying to figure out why my permalinks weren’t working in WordPress. I was getting 404 errors for all the URLs I tried to access. I had tried all of the obvious things and the suggestions from the internet (mod_rewrite was enabled and so were .htaccess files). Sooner or later I figured out that they could be made to work by  redirecting the 404 page to WordPress’ index page. If the page actually doesn’t exist WordPress will take care of displaying a 404, otherwise it will display the page in question and won’t send a 404 header. Long story short, adding the following to the top of the .htaccess file fixed the problem for me:

ErrorDocument 404 /index.php

Of course, the question remains: why didn’t the regular mod_rewrite directives work? I have no idea, because my other rewrite rules in the same file worked. Only the WordPress ones failed. Maybe somebody will enlighten me someday.