Route for Custom 404 Page in 5.7

Permalink 1 user found helpful
Hi all, can someone please point me in the right direction for creating custom 404 pages in 5.7. I see in app.php we have the following core paths available for overide, but how do we route to a theme specific 404?

/**
     * Route themes
     */
    'theme_paths'         => array(
        '/dashboard'        => 'dashboard',
        '/dashboard/*'      => 'dashboard',
        '/account'          => VIEW_CORE_THEME,
        '/account/*'        => VIEW_CORE_THEME,
        '/install'          => VIEW_CORE_THEME,
        '/login'            => array(
            VIEW_CORE_THEME,
            VIEW_CORE_THEME_TEMPLATE_BACKGROUND_IMAGE
        ),
        '/register'         => VIEW_CORE_THEME,
        '/maintenance_mode' => VIEW_CORE_THEME,

mrjcgoodwin
View Replies: View Best Answer
anete replied on at Permalink Reply
anete
I'm also having trouble activating a 404 page for redirecting old pages.
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
@mrjcgoodwin
@anete

I believe you just need to create a theme page template named page_not_found.php.

Without page_not_found.php, I believe view.php is used. Without view.php, a bare page is used.
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
Spot on - you're exactly right, thank you! :-)
mdunbavan replied on at Permalink Reply
Can anyone tell me how I can keep my main navigation in a 404 page. I have it in a GlobalArea where the autonav is selected and its placed inside the header area. When I hit the 404 I have no main nav...what could cause this? Thanks
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
Don't quote me on this - but I'm sure I've come across this as a known bug before. Global areas not working on the home page. It could be related?

You can hard code your navigation maybe as a workaround:http://c5blog.jordanlev.com/blog/2012/04/hard-coded-autonav-options...
mdunbavan replied on at Permalink Reply
This won't work because I am working with a multilingual site, the header shows up but the autonav it seems is not working from the autonav block that I put into the global area. If I hard code it I won't get specific nav items I need.
mdunbavan replied on at Permalink Reply
plus this nav needs to work across one file in the header.php file and then included in subsidery page templates
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
Ah ok - that's a pain. I've just double checked, the site I've been working on as discussed above is definitely using multiple global areas on my 404 page (page_not_found.php) so it definitely can work!

I made my page not found template by just cloning my default template and then putting in 404 content along with hard coding the 404 headers to the top of the template as follows

<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<?php header("HTTP/1.0 404 Not Found"); ?>
mdunbavan replied on at Permalink Reply
ah okay so for instance in mine I will have this:
page_not_found.php

<?php  
defined('C5_EXECUTE') or die('Access Denied.');
header("HTTP/1.0 404 Not Found");
$view->inc('elements/head.php'); 
$view->inc('elements/header.php');
$view->inc('elements/main_hero.php');
?>
<div id="latest-news" class="main">
   <section class="grey single-area-top">
      <div class="news-top">
         <article class="container accordian-container">
              <div class="small-12 medium-9 large-9 columns">
                 <h1><?php echo t('Sorry the page you were looking for cannot be found'); ?></h1>
                 <?php echo t('Some 404 blurb here'); ?>
             </div>


In header.php I have the GlobalArea('Header Nav') which is not working. Shall I just paste the whole header.php content into the page_not_found.php template?
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
That's very similar to my page, I don't see why it shouldn't work.

The only real difference is (right or wrongly, I'm more design not dev) my headers/navs etc are being called in with traditional php includes rather than the C5 style view includes.

Have you tried all the usual tricks - clearing caches etc?

Maybe a better dev than me has some ideas?
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
Another thought - is your nav definitely not loading, or just not showing any links? Could it be that the single pages are at the wrong level for you autonav block settings and therefore not showing any pages?
mdunbavan replied on at Permalink Reply
I think that's it after looking into it more
jeevanism replied on at Permalink Reply 1 Attachment
jeevanism
In my application folder I have a page
/application/themes/CustomThemeFolder/page_not_found.php

the content of this page is below
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('elements/header.php'); ?>
<main>
    <div class="container">
        <div class="row">
            <div class="col-sm-9 col-sm-offset-3">
                <div class="jumbo">
                    <h1><?php echo t('404 Error')?></h1>
                    <p><?php echo t('Page not found.')?></p>
                </div>
            </div>
        </div>
    </div>
</main>



Now I have application/single_pages/page_not_found.php
content of this file below
<?php
defined('C5_EXECUTE') or die("Access Denied.");
<?php header("HTTP/1.0 404 Not Found"); ?>
$this->inc('elements/header.php'); ?>
<main>
    <div class="container">
        <div class="row">
            <div class="col-sm-9 col-sm-offset-3">
                <div class="jumbo">
                   <?php $a = new Area('Main'); ?>
<?php $a->display($c); ?>
<a href="<?php echo DIR_REL?>/"><?php echo t('Back to Home')?></a>
                </div>
            </div>
        </div>


Since none of these solved my problem, I created a new Page Type > Page Template and Page through C5 Admin Panel. Screenshot Attached

The Link URL to that page is here >http://kaakkakkoottam.com/index.php/page-not-found...

But whenever an actual Page Not Found error happened the page shows default elemental theme only,(http://kaakkakkoottam.com/index.php/fdf)
not my custom theme. What shall I do now ?



thanks
Jeevan
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
I don't think you need the template in single pages, as on my site it automatically detected page_not_found.php in my theme folder.

Not sure why it's not picking your one up - have you tried clearing your cache?
jeevanism replied on at Permalink Reply
jeevanism
@mrjcgoodwin

hmm.The cache is disabled now. I mean from the start I have disable the cache
I did not enable the pretty URL yet, the pages are still routing through index.php

Would that be an issue ?? I need to enable the custom theme into the 404 page not found error page

Like thishttp://kaakkakkoottam.com/index.php/page-not-found...
jeevanism replied on at Permalink Reply
jeevanism
replied on Jan 5, 2016 at 3:58 am Permalink Best Answer
Reply
MrKDilkington
@mrjcgoodwin
@anete
I believe you just need to create a theme page template named page_not_found.php.
Without page_not_found.php, I believe view.php is used. Without view.php, a bare page is used. /////


@MrKDilkington

Where should create this template file ? I created one in my application/customthemefolder and also in application/singlePage folder. I created a new Page through Dashboard but nothing all works
MrKDilkington replied on at Permalink Reply
MrKDilkington
@jeevanism

I believe page_not_found.php should be placed in your theme folder with the rest of your page templates.
jeevanism replied on at Permalink Reply
jeevanism
MrKDilkington replied on Jan 8, 2016 at 6:01 am Permalink
Reply
MrKDilkington
@jeevanism
I believe page_not_found.php should be placed in your theme folder with the rest of your page templates.


There is already a page_not_found.php file in my application/themes/CustomThemeFolder The content of that page is below
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('elements/header.php'); ?>
<main>
    <div class="container">
        <div class="row">
            <div class="col-sm-9 col-sm-offset-3">
                <div class="jumbo">
                    <h1><?php echo t('404 Error')?></h1>
                    <p><?php echo t('Page not found.')?></p>
                </div>
            </div>
        </div>
    </div>
</main>


but still my page not found page shows default elemental theme, not the custom theme
404 page -http://kaakkakkoottam.com/index.php/sdsds...
my theme page -http://kaakkakkoottam.com/index.php/credit...

please advise.

thank you
Jeevz
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
@MrKDilkington This is what I did and it worked fine.

@jeevanism - I would be surprised if it was the pretty URLs, but it wouldn't do any harm to turn them on and check.
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
Is your .htaccess file set up correctly? (turning on pretty urls will provide you with the right content for this file).

I notice that if you go to

http://kaakkakkoottam.com/index.php/sdsds...

and

http://kaakkakkoottam.com/sdsds...

you get 2 different 404 pages.
jeevanism replied on at Permalink Reply
jeevanism
I notice that if you go to
http://kaakkakkoottam.com/index.php/sdsds...
and
http://kaakkakkoottam.com/sdsds...
you get 2 different 404 pages.


Yes, thats because, the first one is routing through index.php, since it shows the c5 theme template. But the second one is actually showing the cpanel default error page only.

I did not enable the pretty URLs yet because I have yet to finish the development of the website, adding pages and contents. I did not touch any thing with .htaccess yet.

Themeing the 404 error page should not be this much hurdle !! :-(
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
There's definitely something odd going on in your case - I've never found custom 404's with C5 to be particularly difficult - I only started this thread to clarify some differences in implementation with the new 5.7, and it proved simple enough once I knew how.

I'm sure there's something simple going on here that you'll kick yourself for! Have you checked the file permissions for your uploaded not found file?

Also, just because you are still working on the site I don't see why turning on the pretty urls would cause you any problems - you could turn them off again once you've tested.
jeevanism replied on at Permalink Reply
jeevanism
@Mrk, @mrjc
Finally Happy News

Steps I have done now

1. I deleted the page_not_found.php file from /application/single_pages
2. I edited the page_not_found.php file from /applications/themes/CustomTheme folder
3. I added my custom theme div blocks( div block code from my fullpagetheme.php) to the page_not_found.php

to make more clear
my old page_not_found.php contents as follows
<?php
defined('C5_EXECUTE') or die("Access Denied.");
<?php header("HTTP/1.0 404 Not Found"); ?>
$this->inc('elements/header.php'); ?>
<main>
    <div class="container">
        <div class="row">
            <div class="col-sm-9 col-sm-offset-3">
                <div class="jumbo">
                   <?php $a = new Area('Main'); ?>
<?php $a->display($c); ?>
<a href="<?php echo DIR_REL?>/"><?php echo t('Back to Home')?></a>
                </div>
            </div>
        </div>



My new working page_not_found.php inside /application/themes/customethemefolder/
is below
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('elements/header.php'); ?>
<?php header("HTTP/1.0 404 Not Found"); ?>
<div class="container singlepage">      
<div class=" example-popover">     
 <div class="col-md-2"> 
    <div id="fixedsidebar">
        <div class="popover left">
           <div class="arrow"></div> 
          <div class="caption text-center"> 
   <?php
                $a = new Area('Sidebar');
                $a->display($c);
                ?>



Now the 404 page renders with my custom theme only :)
http://kaakkakkoottam.com/index.php/sdfkdf...


thanks for the help, now I am going to enable same theme / error display message show on my search page (no result found)




--
Jeevz
MrKDilkington replied on at Permalink Reply
MrKDilkington
@jeevanism

I would put page_not_found.php in this folder application/themes/crow.
application/themes/crow/page_not_found.php

Try removing the page_not_found.php you put in the single pages folder:
application\single_pages

After removing it, go to the Single Pages page and refresh the Page Not Found single page (click the circling arrows icon).
Dashboard > Pages & Themes > Single Pages
jeevanism replied on at Permalink Reply
jeevanism
@MrKD

I kind of have done exactly as you said. I removed the file and added to my theme folder. And instead going through DashBoard, I directly edited the php file and then added contents through dashboard :P

any how, its working now.

Another milestone, I enabled same theme for my search page / search not found page. Please take a look

http://kaakkakkoottam.com/index.php/search?search_paths[]=&quer...


please search some thing not in the side
http://kaakkakkoottam.com/index.php...



-- Happy Concreting !! -
Jeevs
MrKDilkington replied on at Permalink Reply
MrKDilkington
@jeevanism

Please create a new discussion for a different topic.
mrjcgoodwin replied on at Permalink Reply
mrjcgoodwin
Glad you got it all sorted jeevanism - There has not been many issues I've come across with C5 that this excellent community have not been able to solve :-)

And I'm really growing into 5.7 now I've had a chance to do a few sites with it.