Forums

envoke 404 manualy (5 posts)

  1. shazdeh
    Member
    Posted 1 month ago #

    I'm using custom url in my theme and have made my own template hiracical (i can't spell it!).
    So, in some situations I want to tell the wp that a 404 error happens, so use the 404.php to make the page. how to do that?

  2. miqrogroove
    Member
    Posted 3 weeks ago #

    I'd like to know this one too!

  3. Shane G
    Member
    Posted 3 weeks ago #

    Hi,

    Set your desired permalink and add this code in htaccess:

    `# BEGIN WordPress

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

    # END WordPress`

    Thanks,

    Shane G.

  4. miqrogroove
    Member
    Posted 3 weeks ago #

    Hi Shane, it seems you've missed the point of the OP. He wants to throw 404 instead of echoing "Not Found" in the template's "Else" case.

    From what I've seen so far, it looks like this can only be done at the top of the template before any whitespace and before get_header(). The template has to call has_posts() and then handle the 404 manually by setting headers, including other templates, and quitting the script.

  5. miqrogroove
    Member
    Posted 3 weeks ago #

    For example, at the top of archive.php, get rid of this:
    <?php get_header(); ?>

    Replace with this:

    <?php
    if (!have_posts()) {
        header("HTTP/1.0 404 Not Found - Archive Empty");
        require TEMPLATEPATH.'/404.php';
        exit;
    }
    get_header();
    ?>

    NOW you have proper SEO. It's shocking to see the WordPress core miss things like that.

Reply

You must log in to post.

About this Topic

Tags