Lunarpages Web Hosting Forum

Author Topic: Problem with WordPress 404  (Read 18312 times)

Offline myriza

  • Space Explorer
  • ***
  • Posts: 7
Problem with WordPress 404
« on: April 10, 2008, 01:38:58 PM »
I have a few add-on domains, and they are all running WordPress. Some of them load the 404.php just fine, but I'm having a problem with a couple where I can't get a 404 error message. Funny how everyone on the internet is trying to NOT get a 404 error page and I'm frustrated because I CAN'T get one.

If I enter a non-existing address, I should get a 404 error, but I don't. Instead, it posts every single page published on this site.

I made sure that I have a 404.php file in the proper location. I added a line to .htaccess to direct the error to the appropriate file, though I was unsure of where exactly in the .htaccess file to PUT the new line:

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

ErrorDocument 404 /index.php?error=404

# END WordPress

The .htaccess file is in the same folder as all my wordpress files (including the wp-admin folder, wo-content folder, etc).

I've googled a hundred different things, but haven't found a solution. I know this isn't exactly a question about lunarpages, but this forum seems much more helpful than the wordpress.org support forum.
« Last Edit: April 12, 2008, 12:26:04 PM by myriza »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Problem with WordPress 404
« Reply #1 on: April 10, 2008, 04:06:06 PM »
If you give a bogus URL, are you always getting the Home Page (/index.php)? That seems to be what your .htaccess entries are asking for: if request is not for an existing file and not for an existing directory, send to /index.php (your Home Page). The 404 Error Document would never kick in. Try adding ?error=404 in your rewrite section (/index.php?error=404 instead of just /index.php) and see if it makes a difference. You might just try commenting out that whole rewrite section and see if the 404 Error Document fires off.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline myriza

  • Space Explorer
  • ***
  • Posts: 7
Re: Problem with WordPress 404
« Reply #2 on: April 10, 2008, 06:31:53 PM »
Thank you so much for the quick reply!!

A bogus URL doesn't redirect to the Home Page, but to some new entity that compiles the content of every page published on the site tacked into one page. It winds up being 200+ pages of content from 30+ published pages :(

When I tried to go to http://domain.net/index.php?error=404 like you suggested, it did indeed send me to the Home Page. But when I type in a bogus URL, it loads every page like I mentioned above.


Ok, on to your next suggestion - I edited out all the rewrite stuff from the .htaccess file so now it's absolutely empty. I entered a bogus URL and got the good ol' Firefox 404 Not Found (not the 404.php that matches my theme).

I added ErrorDocument 404 /index.php?error=404 to the .htaccess and I was once again back to loading the page with a compilation of every page published.

Also, what does the rewrite stuff (what I commented out) do? Is leaving .htaccess empty a problem?

Thanks again for your help!


« Last Edit: April 12, 2008, 12:26:27 PM by myriza »

Offline Dinu

  • Intergalactic Superstar
  • *****
  • Posts: 168
  • Learning Wordpress :)
Re: Problem with WordPress 404
« Reply #3 on: April 10, 2008, 06:42:33 PM »
Hi there

Do you have a custom 404 page file for this theme ? It can be theme specific .. tried to see if u get the same error on the default theme ?
Greetings !!!
Dinu

Offline myriza

  • Space Explorer
  • ***
  • Posts: 7
Re: Problem with WordPress 404
« Reply #4 on: April 10, 2008, 06:51:20 PM »
Yes, I created a custom 404.php file by duplicating the index.php, deleting the loop parts, and then entering some text and renaming the file 404.php. Without even opening the .htaccess file, this worked for 3 out of 5 sites I've been working on. I can't for the life of me figure out what's different with the other two...

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Problem with WordPress 404
« Reply #5 on: April 11, 2008, 06:18:28 PM »
Is there some reason that you chose to invoke your error page (404.php) via index.php, rather than just specifying it directly (ErrorDocument 404 /404.php)? Also, Error documents are typically SHTML or even HTML -- I don't know if there will be any problems using PHP files. Since SHTML requires server-side processing (as does PHP), that may be irrelevant. Maybe you should try a simple 404.shtml file first, to make sure it's being invoked consistently, and then go from there to PHP and more complex structures.

I can't imagine what's giving you a page that "compiles the content of every page published on the site", unless it's either a search you're kicking off, or you somehow butchered your index.php file in the process. And yes, .htaccess can certainly be empty -- you'll get default settings for everything.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline myriza

  • Space Explorer
  • ***
  • Posts: 7
Re: Problem with WordPress 404
« Reply #6 on: April 12, 2008, 06:35:11 AM »
Thank you again for taking the time to help me! There are about a million unanswered support posts in the WordPress forum, and the idea of becoming 100,000,001 didn't appeal to me.

I was invoking the error page via index.php because that is what is largely recommended in the world of WordPress (I did many many Google searches on this topic). For some horrible reason, this does not work for me.

For now, I've created an html file, stuck it in my root, and I direct errors to it with: ErrorDocument 404 /404error.html

EDIT: I lied. Now every page on my site except for the front page is returning a 404 error. Back to Google...


With your suggestions, however, I've managed to winnow the problem down to a few things.

1. In .htaccess, the line: RewriteRule . /index.php [L]  is causing a large problem. I have to remove this line or else my new html error page won't show. Instead, I'll get the evil Compilation Page (mentioned in previous posts). I don't fully understand what this RewriteRule does... I hope it's okay I removed it...

2. Manually entering index.php?error=404 into the URL (http://domain.net/index.php?error=404) redirects me to the front page, not the 404.php page.

3. Putting ErrorDocument 404 /index.php?error=404 at the top of .htaccess redirects a non-existing URL to the evil Compilation Page.

4. This all happens using the Default theme as well, so the problem is in my content, my permalinks, or some other unknown factor.

Unless someone has suggestions for more things for me to try, I'm going to just use the html error page and forget about trying to make it play nice with WordPress.

Thanks again for helping me work through this. I'll probably re-examine the problem in a couple months and hope that more information is available (I can't be the only one having this problem... right?).

« Last Edit: April 12, 2008, 12:27:06 PM by myriza »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Problem with WordPress 404
« Reply #7 on: April 12, 2008, 07:26:54 AM »
OK, get rid of (erase or comment out with "#")
Code: [Select]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

ErrorDocument 404 /index.php?error=404

# END WordPress

and put just

ErrorDocument 404 /404error.html

in your /.htaccess file. How does it work then? Please show us your 404error.html file contents. Clear your browser cache, too, in case you're getting an old version of something. Finally, are you sure that you're giving a legitimate URL that's triggering 404? If none of this helps, it's time to talk to support to see if your server is misconfigured.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline myriza

  • Space Explorer
  • ***
  • Posts: 7
Re: Problem with WordPress 404
« Reply #8 on: April 12, 2008, 08:02:14 AM »
Ok, things are getting confusing because I'm trying a dozen different combinations of things. So I will try to be systematic. For all these cases, I'm entering a 100% non-existing URL: http://domain.net/dfvdfv/

Also, I want to mention that this is for an add-on domain.

1. With a completely blank .htaccess I get the standard Firefox 404 Not Found page for the non-existing page. However, I also get a 404 Not Found for all existing pages except for the front page (index).



2. The default WordPress .htaccess
Code: [Select]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I get the evil Compilation Page, and all my pages load properly (Sidebar links, etc).



3. I've seen at least a dozen different sites, including Wordpress.org, say that adding ErrorDocument 404 /index.php?error=404 to the .htaccess will make WordPress look for the 404.php file in the template folder (which I have - it's a copy of my index.php with the Loop removed).

Code: [Select]
ErrorDocument 404 /index.php?error=404
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

This still returns the evil Compilation Page, and all the pages load fine.



4. At this point, I'll mention that manually entering http://domain.net/index.php?error=404 redirects to the front page (which is a WordPress default action, though it's completely ignoring my 404.php file).



5. So I created a super-simple html file and placed it in my root directory.
Code: [Select]
<HTML>
<HEAD>
<meta name="robots" content="noindex">
<TITLE>404 Page Not Found</TITLE>
</HEAD>
<BODY>
<h2>Sorry, the page you're looking for can't be found</h2>
</BODY>
</HTML>

And this file loads fine: http://domain.net/404error.html



6. Now I tried to add this to the .htaccess
Code: [Select]
ErrorDocument 404 /404error.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

And yet again I get the evil Compilation page, with all the other pages loading fine.



7. I removed the WordPress rewrite section again
Code: [Select]
ErrorDocument 404 /404error.htmlAnd the new html page displays for the non-existing URL, but all of the other pages (Sidebar links) return a 404 now.



8. So there are 2 basic outcomes right now: either I get the evil Compilation page and all my pages load; or the 404.html displays, but all of my legit pages become 404 errors.

I'm leaving the site set up with

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

So you can see how bizarre the evil Compilation page is.
« Last Edit: April 12, 2008, 12:28:03 PM by myriza »

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6429
Re: Problem with WordPress 404
« Reply #9 on: April 12, 2008, 08:34:25 AM »
Have you cleared your browser cache? Do that first (after any change to .htaccess). And change just one thing at a time, not a dozen.

You mentioned that this is for an add-on domain -- is there a separate public_html/subdomain/.htaccess that you're not looking at? If you have no (empty) .htaccess file, you should get the default system (not Firefox's) 404 file on a non-existent file. If you define a 404 error document, e.g., /404error.html, it should be used instead (if you list the ErrorDocument in .htaccess).

The WordPress redirection (as given) should redirect 404 errors to the stock /index.php, not to 404.php. If you want it to bring up 404.php, you need to 1) change the rewrite line from just /index.php to /index.php?error=404 and 2) put 404.php in the proper place (not root, but the template directory, or wherever WordPress is supposed to look) and 3) remove the separate ErrorDocument line.

Or, you can remove the WordPress section and just use the ErrorDocument line to point to your own error handler. You can have separate error handlers for WordPress (in public_html/subdomain/.htaccess) and the rest of your site (in public_html/.htaccess). Note that if you do, the root .htaccess will be run first, and might not be superseded by the add-on's .htaccess entry if it's defined in a different way. That is, I would use

public_html/.htaccess:
ErrorDocument 404 /myCommon404.shtml
(with public_html/myCommon404.shtml)

and public_html/subdir/.htaccess:
ErrorDocument 404 /myWordPress404.php
(with public_html/subdir/myWordPress404.php)

If you used the WordPress code for the add-on, it might not override the root setting (ErrorDocument). So, I would do them the same way, just pointing to different error pages.
Visit My Site

E-mail Me
-= From the ashes shall rise a sooty tern =-

Offline myriza

  • Space Explorer
  • ***
  • Posts: 7
Re: Problem with WordPress 404
« Reply #10 on: April 12, 2008, 12:25:24 PM »
Yes, I was clearing my cache. I think I figured out the problem (or at least a fix for it).

In case anyone has this problem in the future, my Reading Settings were to display a static page. Logically, I chose the page I wanted from the Front page drop down menu.

The solution is to choose a random page from the Posts page drop down menu as well (not the same one as in the Front page menu). This second Posts page will not actually display, but for whatever reason, it stops the loop from breaking and displaying everything.

After doing this, all of the things I've been trying to do suddenly worked: the redirection to the 404.php (by adding ErrorDocument 404 /index.php?error=404), the <?php else :?> after the loop (in index.php), everything. I have no idea if this is a bug or not, but it's extremely non-intuitive to me. Why would you choose 2 different pages for the static front page, especially when only one of them is displayed?

Anyway, thank you again for taking the time to help me. Just having someone to discuss this with is what kept me from giving up. I'll be sure to add this to the list of reasons I recommend Lunarpages ^_^
« Last Edit: April 12, 2008, 12:29:13 PM by myriza »

Offline koosmooij

  • Newbie
  • *
  • Posts: 1
Re: Problem with WordPress 404
« Reply #11 on: June 01, 2008, 09:04:15 PM »
If the problem occurs only with WP 2.5.1 (there's a 404 bug in it)

go to:

wp-include/query.php

Look for

if  ( ('page' != get_option('show_on_front') ) || ( $reqpage != get_option('page_for_posts') ) ) {
            $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));

About line 923

and replace with:

if  ( ('page' != get_option('show_on_front') ) || ( $reqpage !== get_option('page_for_posts') ) ) {
            $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename'])));



Add one "=" after $reqpage ! without the quotes or spaces.