Jump to content

how to define the 404 page


fenton
 Share

Recommended Posts

Hi there,

I know, it's probably a really stupid question, but how can I define which page will be shown as 404?

I checked and compared a vanilla PW installation, but can't find out why on the site I'm working on all non existant URLs redirect to the homepage

thanks a lot, cheers, j

Link to comment
Share on other sites

This is defined here:  /wire/config.php

$config->http404PageID = 27;

But this is PW. We do not hack the core. So what do we do? :(:rolleyes: Uh, this is PW, we can override this O0 . So, we put our own 404 page id configuration in our /site/config.php

$config->http404PageID = 1035;// my custom 404 page

A word of caution though in /wire/config.php

 * Hard-coded configuration options for ProcessWire
 * These may be overridden in the /site/config.php, but it is not recommended.

More info here: http://processwire.com/api/variables/config/  :)

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

A word of caution though in /wire/config.php

That's true for a couple of those ID definitions (mainly 1 and 2), but for most it's ok to change them when/if you need to. The 404 page ID is one where there shouldn't be any problem with overriding it. 

Link to comment
Share on other sites

Hi. I have a silly question related to 404 page.

I'd like to give acces to my client so can edit the error #404's messages.

I have no idea how set roles/permissions so he can do it.

Any suggestion?

Thks

Will he be regularly changing the 404 message? If yes, why? Why don't you get the message from him and change it yourself ;) when setting up the site? If he must do it himself, there is a module Page Edit role or something. Have a look at the modules site

Edit: Here they are:

http://mods.pw/34

http://mods.pw/4X

http://mods.pw/39

  • Like 1
Link to comment
Share on other sites

Will he be regularly changing the 404 message? If yes, why? Why don't you get the message from him and change it yourself ;) when setting up the site? If he must do it himself, there is a module Page Edit role or something. Have a look at the modules site

The idea is to give to my client the possibilty to edit any (or the majority) texts in his website. I tried with "Page Edit Per User" module following the instructions, but when I select "/http404/" page in order to be editable for "client" user, this does not display in the "Pages" screen of this user. The template that uses 404 pages, has just two fields: Title and Body. 

Link to comment
Share on other sites

I haven't used those modules before, I'm afraid. You would want to post any issues about them in their respective support threads...

By the way, a different approach to the above: You can also create a "settings" page where you can throw in several fields to hold various pieces of information about the site that your client can easily edit in one place. This only makes sense if you have several settings you want to allow him to edit. E.g., a site slogan, a 404, message etc. If you take this route, you can have a text area field on that page, called, for instance, "404_message" which your client can edit. On the template file of the 404 page itself, you would reference the "404_message" field in the "settings" page as follows:

echo $pages->get(123)->404_message;//where 123 is the ID of the settings page. You can also use the path 

Like I said, this only makes sense if you have several settings. Additionally, you can even make it more full-proof. E.g.

$message = $pages->get(123)->404_message;
if ($message) {
     echo $message;
}

else {//echo your normal 404 message in case client forgot to fill his custom 404 message in the settings page
} 

Quickly written, not tested :)

Edit:

Yeah; you'd want the "settings" page hidden in case you went this route...

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

It's just a 404 message. I'm with that the editor doesn't need to edit that text. That's why it's set in the core (page id) to be only listed in the page tree for superusers.

The 404 is just a regular page that is defined in the config via page id. You can overwrite that with

$config->http404PageID = 1024;

But this will just that page also. :)

SOmething like kongondo would be a solution to still make it. You could add a settings page or even better a custom 404 page with the same template as the 404 page and have it in the tree set hidden.

To replace the rendered page of the 404 page with your own created page, you can add a hook with a autoload module. Look at HelloWorld.module which is such a module that autoloads on each request.

...
public function init() {
    $this->addHookAfter("ProcessPageView::pageNotFound", $this, "hook404Page");
}

public function hook404Page($event){
    header("HTTP/1.1 404 Page Not Found");
    $page = wire("pages")->get("/404/"); // get your 404 page
    $this->wire('page', $page);
    $event->return = $page->render(); // render and return that page
}
 
  • Like 2
Link to comment
Share on other sites

  • 8 months later...

hi all and thanks for the config line :D
I think is a good idea for seo, create a template 404 and add the noindex, follow directive in the header and add in php code: 

if is pageid 27 echo <meta name="robots" content="noindex, follow" />
else <meta name="robots" content="index, follow" /> 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...