WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 5 years ago

#7592 closed defect (bug) (invalid)

index.php doesn't generate 404's

Reported by: btmorex Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.6.1
Component: General Keywords:
Focuses: Cc:

Description

I've found that "normal" 404's work for my website. For example:

http://example.com/alskdfjk

will correctly generate a 404, but any index.php queries for nonexistent stuff won't. Like:

http://example.com/index.php?alskdjfksjf

just returns the front page (recent posts). Even:

http://example.com/index.php?error=404

does not generate a 404. Again, it just returns the front page. I've tried disabling all plugins and also switching back to the default theme, but that didn't fix it.

Change History (11)

#1 @mrmist
9 years ago

I'm not sure that that's actually a bug. I mean, requesting index.php?whatever is actually asking for the page index.php, which is (by default) present, and so (technically) not a 404, regardless of what query string you pass after the question mark.

Passing ?p=somenon-existantpostnumber as the query will get you a WordPress error that no posts match your query, though.

So I guess what I'm saying is that it shouldn't be returning 404. The current behaviour of showing the blog front page is pretty much correct, in my opinion.

#2 @btmorex
9 years ago

Well, I guess you can argue either way for the generic ?whatever, but I'm not getting 404 for *any* index.php request. At the very least, the following two requests should give me 404:

/index.php?p=doesntexist
/index.php?error=404 (<-- according to docs that's the correct way to reference the 404 page)

Both those requests return the front page.

#3 @mtekk
9 years ago

I can reproduce similar behavior. Though I don't really think it's a bug.

"Passing ?p=somenon-existantpostnumber as the query will get you a WordPress error that no posts match your query, though."

It's funny that is_404() returns false in that case (as does is_search()) since one of the two should return true in that case (probably should be a search per what mrmist said, as index.php does exist).

Now if /index.php?error=404 is supposed to return a 404 (I don't know where in the codex it states this but assuming it's correct) and is not then that would be a bug.

#4 @btmorex
9 years ago

Actually, I don't know if trying to access index.php?error=404 should actually respond with a 404. However, it definitely shouldn't be returning the default home page. http://codex.wordpress.org/Creating_an_Error_404_Page says that it should return the custom 404 page I'm using (which, btw does work).

More generally, the reason I think that index.php should be returning 404 for these bad queries is that currently it's serving the same content through potentially many, many different urls. That I'm told is bad practice. Also, suppose a search engine crawler grabs a bad url from somewhere (typo)... it's going to keep crawling that page forever because wordpress never returns an error.

#5 @ryan
9 years ago

  • Milestone changed from 2.7 to 2.8

Postponed to 2.8.

#6 @DD32
9 years ago

Thoughts:

  • Canonical redirection could take place to remove the extra args
    • Which will cause problems for plugins which rely on extra $_GET args
  • ?error=404 will not work with pretty permalinks, if a rule is matched, $error gets ignored.. The codex page will refering to those who use non-rewrite rules mainly i would expect
    • This probably needs to be corrected, if $_GETerror? is set, short circuit the rewrite rules checks maybe, That appears to work and while it sets it to a 404 condition, it still queries the posts for the front page.
      • change line 147 of classes.php to if (! empty($rewrite) && !isset($_GET['error']) ) { for that
  • index.php?blahblahblah=vlbfgdfg shouldnt create 404 pages, its a legitimate request, quite possibly handled by a plugin

So other than possibly making ?error=404 working for permalinks, Thats the only defect i see in this ticket, and even then, its more likely a enhancement, since if PW was using rewrites, then it wouldnt need to have that handler in the .htaccess; I have a feeling that codex page might just contain a lot of ancient (Pre 2.0?) information.

#7 @Viper007Bond
9 years ago

  • Milestone 2.8 deleted
  • Resolution set to invalid
  • Status changed from new to closed

I'm just gonna go ahead and kill this ticket as there's nothing wrong with index.php?foo=bar. Could be for a plugin, or part of a custom theme.

Feel free to reopen if someone disagrees.

#8 @tszming
5 years ago

4 years later I come across the above mentioned link: ​http://codex.wordpress.org/Creating_an_Error_404_Page and spent some times in figuring out why index.php?error=404 does not work (with custom permalink, that is pretty common right?) and finally see this ticket.

I am not re-opening this issue, but can someone put a warning in the codex page?

#9 @Ipstenu
5 years ago

You know that you have edit access to the codex right? :) log in with the same ID you did here, and edit to explain what you mean :)

#10 follow-up: @tszming
5 years ago

Thanks for your reminding, now added.

This seems to be a problem when incomplete or out updated information under wordpress.org appear at the top of Google's search result when you are looking for some authoritative resources..

#11 in reply to: ↑ 10 @Viper007Bond
5 years ago

Replying to tszming:

This seems to be a problem when incomplete or out updated information under wordpress.org appear at the top of Google's search result when you are looking for some authoritative resources..

As Ipstenu said, the Codex is maintained by the community. If you find incomplete or out of date information, step up to the plate and fix it. ;)

Note: See TracTickets for help on using tickets.