ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

404 if the page does not exist in the pages module

July 17, 2008 6:54pm

Subscribe [2]
  • #1 / Jul 17, 2008 6:54pm

    nyeoman

    94 posts

    I have all my pages in the pages module.

    I’d like to direct to a 404 page if the requested url is not in the pages module.

    Does anyone know “how to” do this?

  • #2 / Jul 17, 2008 7:01pm

    kirkaracha

    273 posts

    Maybe a combination of the show_pages parameter and the if no_results conditional?

  • #3 / Jul 17, 2008 7:09pm

    nyeoman

    94 posts

    That might work for most situations, but in my case I want to embed the 404 template before the weblog tag is called.

    A php solution would be preferred, maybe a query to the db.

  • #4 / Jul 17, 2008 7:44pm

    Ryan Irelan

    444 posts

    Is the built-in 404 preference not working for you?

    You can use a simple database query and if no match then return a header like this:

    <?php  header("HTTP/1.0 404 Not Found"); ?>

    But I would use the built-in support if at all possible.

  • #5 / Jul 17, 2008 7:48pm

    nyeoman

    94 posts

    I didn’t think the built-in 404 preference works with the pages module.  I’m not sure how to access the built in 404 preference from the admin to test it.

  • #6 / Jul 17, 2008 8:09pm

    Ryan Irelan

    444 posts

    It’s under Templates >  Global Template Preferences and you can choose a template to show in the event of a 404. There are some caveats listed here and here (if you’re removing index.php).

  • #7 / Jul 17, 2008 8:48pm

    nyeoman

    94 posts

    Ah there it is!  It works great!

    THanks

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases