Title: Custom permalink and 404.php error
Last modified: August 18, 2016

---

# Custom permalink and 404.php error

 *  Resolved [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/)
 * 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](http://wordpress.org/download/) (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)

 *  Thread Starter [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372571)
 * **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.
 *  Thread Starter [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372572)
 * **Related Threads:**
 * [404 Not Working Properly](http://wordpress.org/support/topic/66733)
 * [WordPress Steals 404](http://wordpress.org/support/topic/65712)
 * [WP 2.0 messed up my permalinks](http://wordpress.org/support/topic/54340)
 * Next, I’ll go into the steps I’ve taken so far to try to debug this issue.
 *  Thread Starter [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372577)
 * **Steps I’ve Taken So Far**
    1.  First, I read all of the documentation on [Creating an Error 404 Page](http://codex.wordpress.org/Creating_an_Error_404_Page)
        and [Using Permalinks](http://codex.wordpress.org/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:
    3.  `
         # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule./
        index.php </IfModule> # END WordPress ErrorDocument 404 /404.html
    4.  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.
    5.  Next, I verified that my hosting provider has the Apache module mod_rewrite
        installed. They do.
    6.  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](http://wordpress.org/support/topic/54340)
        held some promise. One of our members, [Ryan](http://wordpress.org/support/profile/655),
        posted some [fixes](http://wordpress.org/support/topic/54340?replies=42#post-298609)
        to the functions-post.php and classes.php files. I promptly downloaded & installed
        them. Unfortunately, they didn’t resolve the bug.
    7.  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.
    8.  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](http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html)
        documentation. And here is what I understand to be going on:
    9.  This turns on the mod_rewrite runtime engine:
         `RewriteEngine On`
    10. This sets the base URL for rewrites to my document root URL (for you, it could
        be different):
         `RewriteBase /`
    11. 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`
    12. 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`
    13. 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`
    14. 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.
    15. Then I typed in this explicitly: `blog_domain_name.com/index.php?error=404`,
        since that’s what [this](http://codex.wordpress.org/Creating_an_Error_404_Page#Help_Your_Server_Find_the_404_Page)
        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.
    16. 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 `blog_domain_name.com/index.
        php?error=404` 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!
 *  Thread Starter [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372585)
 * **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](http://trac.wordpress.org/ticket/2651)–
   filed by sluggo on April 9th, 2006
 * [Ticket #2376: Custom 404 page error/conflict with permalinks](http://trac.wordpress.org/ticket/2376)–
   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!
 *  [viper007bond](https://wordpress.org/support/users/viper007bond/)
 * (@viper007bond)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372591)
 * > **To Reproduce this Bug:**
   > [snip]
 * 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.
 * Examples:
 * [http://www.viper007bond.com/archives/2006/03/11/wordpress-v202-released/](http://www.viper007bond.com/archives/2006/03/11/wordpress-v202-released/)
 * [http://www.viper007bond.com/this/is/a/fake/url/](http://www.viper007bond.com/this/is/a/fake/url/)
 *  Thread Starter [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372694)
 * 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:
 * Mine:
    `404 OK`
 * Yours:
    `404 Not Found`
 * Another user just posted [this thread](http://wordpress.org/support/topic/68654)
   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 [http://wordpress.org/404](http://wordpress.org/404)
   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…
 *  [phord](https://wordpress.org/support/users/phord/)
 * (@phord)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372711)
 * 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.
 *  Thread Starter [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-372713)
 * 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.
 *  Thread Starter [Mike Lee](https://wordpress.org/support/users/mikeleeorg/)
 * (@mikeleeorg)
 * [20 years, 1 month ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-373089)
 * **Solved!**
 * 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](http://wordpress.org/support/topic/67416).
 * Big thanks to everyone here who helped out! And much thanks to my brilliant sysadmin!
 *  [azanutta](https://wordpress.org/support/users/azanutta/)
 * (@azanutta)
 * [20 years ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-373120)
 * 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 [http://wordpress.org/support/topic/73642?replies=1](http://wordpress.org/support/topic/73642?replies=1)
 *  [sblamey](https://wordpress.org/support/users/sblamey/)
 * (@sblamey)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-373127)
 * 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:
    [http://wordpress.org/support/topic/67416](http://wordpress.org/support/topic/67416)
 *  [clearblogs](https://wordpress.org/support/users/clearblogs/)
 * (@clearblogs)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-373136)
 * 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
 *  [wslaat](https://wordpress.org/support/users/wslaat/)
 * (@wslaat)
 * [19 years, 7 months ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-373154)
 * Hello,
 *  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..
 * —–
    wslaat [http://www.wslaat.com](http://www.wslaat.com)

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Custom permalink and 404.php error’ is closed to new replies.

## Tags

 * [errordocument](https://wordpress.org/support/topic-tag/errordocument/)
 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 13 replies
 * 7 participants
 * Last reply from: [wslaat](https://wordpress.org/support/users/wslaat/)
 * Last activity: [19 years, 7 months ago](https://wordpress.org/support/topic/custom-permalink-and-404php-error/#post-373154)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
