Support » Fixing WordPress » Custom permalink and 404.php error

  • Resolved Mike Lee


    I decided to start a new thread on this existing topic to consolidate some of my findings. My apologies if anyone finds this yet-another-thread-on-the-same-topic annoying.

    I came across what appears to be a bug in the WordPress 2.0x build and am going to attempt to debug it. Though I haven’t succeeded yet, I’m going to post my steps here, in the hopes that someone will see this and spark a solution of their own.

    To Reproduce this Bug:

    1. Install WordPress 2.0.2 (latest build as of this post)
    2. Create a test blog entry
    3. Go to the Admin screen -> Options -> Permalinks
    4. Select the “Date and name based” option
    5. Click on “Update Permalink Structure”
    6. Click on “View Site” (at the top of the page)
    7. Click on your test blog entry – this should be working fine
    8. Type in a directory or filename that you know does not exist in your blog, so you can trigger a 404 error

    If this bug exists in your build, you’ll get this error message (or something similar):

    Not Found

    The requested URL /cgi-bin/php/index.php was not found on this server.

    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

    In my next post, I’ll go into my system’s details.

Viewing 13 replies - 1 through 13 (of 13 total)
  • My System’s Set-up:

    FreeBSD 5.4
    Apache 1.3.34
    PHP 4.4.2
    WordPress 2.0

    Next, I’ll point to several related threads in this forum.

    Related Threads:

    404 Not Working Properly

    WordPress Steals 404

    WP 2.0 messed up my permalinks

    Next, I’ll go into the steps I’ve taken so far to try to debug this issue.

    Steps I’ve Taken So Far

    1. First, I read all of the documentation on Creating an Error 404 Page and Using Permalinks, trying all of their suggestions. None of them worked for me.
    2. Next, I took a look at my .htaccess file. It’s CHMOD access was 666 (which is correct, and what an omen, huh?). The contents of it were:

      # BEGIN WordPress
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php
      # END WordPress
      ErrorDocument 404 /404.html

      This is what WordPress created for the custom permalinks, and it appears to be working as it should – except for the last line. The last line should be displaying the custom 404.php file. And for some reason, it wasn’t.

    3. Next, I verified that my hosting provider has the Apache module mod_rewrite installed. They do.
    4. Next, I read all of the above forum threads and even tried a search on Yahoo and Google. The thread WP 2.0 messed up my permalinks held some promise. One of our members, Ryan, posted some fixes to the functions-post.php and classes.php files. I promptly downloaded & installed them. Unfortunately, they didn’t resolve the bug.
    5. Then I turned off my custom permalinks and found my custom 404 page working as it should. However, when I tried to point my 404 page to the custom one in my theme (using: ErrorDocument 404 /index.php?error=404 in my .htaccess file), I received the same error again. Hmmm.
    6. Then I decided to dig into the .htaccess file some more, to understand exactly what it was doing. I read up on this Apache module mod_rewrite documentation. And here is what I understand to be going on:

      This turns on the mod_rewrite runtime engine:
      RewriteEngine On

      This sets the base URL for rewrites to my document root URL (for you, it could be different):
      RewriteBase /

      This sets a condition to detect whether or not the URL to your blog is a valid filename. If it’s NOT, then it returns true:
      RewriteCond %{REQUEST_FILENAME} !-f

      This sets a condition to detect whether or not the URL to your blog is a valid directory. If it’s NOT, then it returns true:
      RewriteCond %{REQUEST_FILENAME} !-d

      If both conditions are true (meaning if the URL to your blog is not an existing filename or directory, then go to your root index.php file:
      RewriteRule . /index.php

      Ah ha. That seems to be something. So essentially, these rewrite conditions are hijacking the errorDocument statement and pushing every request through index.php. That explains why my system has been seemingly ignoring my errorDocument statement.

    7. Then I typed in this explicitly:, since that’s what this documentation suggests. Instead of seeing my custom 404 page, I get my blog’s homepage. Ah. Now I think I’m getting closer to the problem. The issue seems to be in how WordPress handles the error querystring parameter.
    8. Now I’m going to dig into WordPress’ code to find out exactly what it does with the error parameter. It seems to me that should work, and for some reason, it isn’t. Give me a few days to look into this. If I find any answers, I’ll post them right away. If you have any comments, please post them to this thread! Thanks!

    Bugs Have Been Filed

    It appears that several bugs have already been filed on this issue.

    Ticket #2651 (reopened): 404.php not implemented with different permalink structure – filed by sluggo on April 9th, 2006

    Ticket #2376: Custom 404 page error/conflict with permalinks – filed by vsa on Feb. 2nd, 2006

    Hopefully a resolution will come out of these soon. In the meantime, I’ll keep digging away at the code. And if you have any insights, I’d greatly appreciate them! Thanks!

    To Reproduce this Bug:


    For the record, that only works on a small number of hosts. It works fine on most servers, including all of mine and my friends. 😉

    No, I’m not saying that this isn’t a problem, I’m just saying it’s something that your host has done.


    Interesting. I wonder what it is that my host has doing that’s different than your host.

    So I compared the response headers from my server to your server, and here’s what I found:

    404 OK

    404 Not Found

    Another user just posted this thread a few hours ago with the same issue. I looked at his response headers and saw this:
    404 OK

    To do one more comparison, I went to to throw a 404 error on this machine. Also received a:
    404 Not Found

    I see a bit of a pattern here. Seems that my server isn’t throwing a correct 404 header. That would explain why an ErrorDocument 404 isn’t working.

    And furthermore, this is only the case when I have these rules in my .htaccess file:

    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php

    When I remove these rules, my 404 header works as it should.

    So why are these rules causing my 404 header to foul up? Hmmm…

    FWIW – “404 OK” is fine. The text after the code is just for humans. The 404 is the only part a machine should be trying to interpret.

    Ah, thanks for the info, phord.

    So the prevailing assumption is that this may be caused by a particular Apache configuration set by my host, which is not playing nice with my WordPress installation. I’ll send a note to my hosting provider to see if they have any insights.


    My sysadmin looked into the problem, did some research, and discovered that FastCGI was causing the problem.

    The solution has already been documented here on this forum, in the thread problems running under php/fastcgi.

    Big thanks to everyone here who helped out! And much thanks to my brilliant sysadmin!

    I have the same your problem, but your solution didn’t works for me…
    i’ve updated the functions.php file with the new 4 lines but the problem remains… 404 not found.
    i’ve also posted my problem here… please help

    I have a similar problem, but I don’t get 404.php under the default setting or with custom permalinks. What I have discovered is that the problem seems related to PHP running under cgi.

    I’ve tested this on a host with apache running mod_php and evrything works as expected, 404.php is shown for non-existent URLs, but not on my other webspace that uses PHP/cgi.

    See my original comments at:



    makesure the content exsists. eg. if you have a category called COMPUTERS but no posts in it. Sometime w/ permalinks you will get 404 errors


    I would like to thank everyone for these nice solutions, I faced the same problem but finally I solve it out.

    make sure you write the codes manually in .htaccess OR give it 777 to work auto with your cpanel changes..


Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Custom permalink and 404.php error’ is closed to new replies.