Getting .htaccess to override WordPress defaults (5 posts)

  1. jentorme
    Posted 7 years ago #

    I'm having trouble with 404 redirection and a new theme on WordPress 2.7.

    I want to set 404 behavior in my .htaccess file.

    Just for testing purposes, I have the .htaccess file redirect all 403 and 404s to some other famous site, like:

    ErrorDocument 403 http://google.com/
    ErrorDocument 404 http://cnn.com/

    The 403 redirection works perfectly. The 404 redirection does not.

    What happens is that for any 404 page, WordPress draws an index.php for that page with a wp_title value of "Page not found". (The theme does not have a 404.php and it's not using the 404.php from the default theme.) Oh, and none of the Adsense Manager blocks show up on that page either.

    How do I get the server to use .htaccess for a 404 instead of WordPress?

    I thought that Apache looks at the .htaccess before WordPress is even invoked, so this whole thing is soooo confusing to me. Why can't I specify what to do for 404 pages?

    (All I want it to for a 404 is to just load the home page of my site, not show a custom page.)

    Thanks for your help!

  2. jentorme
    Posted 7 years ago #

    I should also mention that I'm using "/%postname%/" as my permalink structure because the site design calls for that. I've had no other problems with it at all and aside from the inability to get the 404 in .htaccess, the site's running beautifully.

    Please if anyone is out there, please help!

  3. jentorme
    Posted 7 years ago #

    I've been playing wtih my permalinks and I changed it to one of the defaults and still have this problem, so it's not related to the use of postname as the sole delineator in permalinks.

    To sum up: I can't redirect 404's with my .htaccess file. 403's redirect fine through that but not 404s, which instead load the index.php file. Why? How to change this? Anyone out there?

  4. jentorme
    Posted 7 years ago #

    Ok, this is definitely a Mod_Rewrite issue.

    When using the "default" WordPress URL format (ugly), the ErrorDocument directive in the .htaccess file is read.

    But changing the permalinks to anything at all, any of the giving formats, will make the ErrorDocument line useless.


  5. jentorme
    Posted 7 years ago #

    Ok boys, I know how to kludge around this. You just make your 404.php a PHP redirect to wherever you want your 404 to go.

    But I still don't get why .htaccess can redirect a 403 and not a 404. It's probably because once you have these rewrite rules in place, there really *is* no 404 ... it's just passed right on to WordPress.

    If that's the case, I think the codex really needs a big bold section on this. Because I've found so many people on here with the same problem, always unanswered. You guys listening? Please update the docs. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic