Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2376 closed defect (bug) (invalid)

Custom 404 page error/conflict with permalinks

Reported by: vsa's profile vsa Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.0
Component: General Keywords: 404 custom permalinks
Focuses: Cc:

Description (last modified by davidhouse)

My custom 404.php page (inside my theme's folder) does not work with the following .htaccess file:

# BEGIN WordPress
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>

# END WordPress

But my customized 404.php page works fine if you eliminate all the permalinks code from the .htaccess, so that the file looks like this:

ErrorDocument 404 http://vitorazevedo.com/404.htm

It seems that I have to choose between permalinks or custom 404 redirect. Any help?

Change History (11)

#1 @vsa
18 years ago

Just wanted to mention that me permalinks structure is a custom one:
/%year%/%postname%/

#2 @davidhouse
18 years ago

  • Description modified (diff)

Just clearing your description up a bit.

#3 @davidhouse
18 years ago

  • Description modified (diff)

Typo.

#4 @martin_hoegh
18 years ago

I get the same error (http://wordpress.org/support/topic/59186). It is important to note that custom 404's worked with 1.5.2. I have tried to isolate the problem, and I have found out that changing

var $use_verbose_rules = false;

to

var $use_verbose_rules = true;

in classes.php and updating the permalinks structure makes it possible to use both permalinks and specify a 404 document. But this is a hack that doesn't solve the real problem, since we/I cannot use the 404.php from the theme folder.

The error produced is really weird. When trying to access the non-existent http://example.com/sdfsdf the error prodced is:

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

When was that URL requested?

#5 @foolswisdom
18 years ago

  • Milestone 2.0.1 deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Marking WORKSFORME for now without testing as no update in a long time. If this is still an issue please update with additional details.

Do you have php/fastcgi enabled?

http://wordpress.org/support/topic/66733?replies=6

http://wordpress.org/support/topic/67416?replies=8

#6 @aonicc
18 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I'm having the same issue. It seems like the mod_rewrite code is intercepting the "bad urls" and feeding them to index.php. Unfortunately, the only way to solve this is to have wordpress itself recognize bad urls (throw something in that checks to see if the GET parameters are valid posts?) and throw up a 404 on its own.

any help on this?

#7 @RuddO
18 years ago

There's a simple explanation for this.

The ErrorDocument stanza in Apache config files is not being executed.

A better explanation:

The default mod_rewrite stanzas that WordPress feeds into .htaccess say something that, translated in words, roughly means:

"Hand every request to index.php for processing, *unless* it's a request for an existing file or directory".

Thus, with permalinks enabled, any request for a page not found will go to the index.php file. Deep inside the guts of WP (class WP_Rewrite and class WP, to be exact) there's code to determine if the request was for a post that did not exist (which actually also covers the cases of nonexistant files or directories).

When a request is received by WP and WP can't find data to send (posts, pages, etcetera), WP simply uses your _theme's_ 404.php file to display the error in the blog format, and sends it back to the user, along with a 404 Not Found status.

So, in other words, ErrorDocument 404 stanzas will never work if you're also using permalinks.

Got it?

#8 @RuddO
18 years ago

In other words, yet again, WP is the one responsible for throwing out nicely blog formatted 404 errors.

#9 @RuddO
18 years ago

@martin_hoegh: sure would love you to provide an URL so we can diagnose the problem accurately. error_log and rewrite_log snips would also go a great way, as well as .htaccess and apache config dumps.

#10 @RuddO
18 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

Choose permalinks and edit your theme's 404.php page to provide the real 404 error message.

#11 @Viper007Bond
18 years ago

Or just put any rules you want ABOVE WordPress'. I have plenty of rules (including ErrorDocument 404 one) running on my WordPress site and it works just fine with permalinks enabled.

Note: See TracTickets for help on using tickets.