Welcome Guest, Not a member yet? Register   Sign In
HMVC custom 404 pages
#1

[eluser]Mikle[/eluser]
Hello!

I'm using ME HMVC. How can I make custom 404 pages on it, if module or method of controller doesn't exist?
#2

[eluser]karloff[/eluser]
ter are a couple of diffent way however i like Jerome's solution

http://maestric.com/doc/php/codeigniter_404
#3

[eluser]wiredesignz[/eluser]
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Base Controller Extension
*/
class Base_Controller extends Controller
{    
    function Base_Controller() {
        parent::Controller();
    }
    
    function _remap($action) {
        
        if (method_exists($this, $action) OR method_exists($this, $action = 'index')) {
            call_user_func_array(array(&$this, $action), array_slice($this->uri->segments, 1));
        } else {    
            show_404(); //modules::run('error/error_404');
        }

    }
}

/* End of file MY_Controller.php */
/* Location: ./application/libraries/MY_Controller.php */
#4

[eluser]Mikle[/eluser]
I extended CI_Exeption class and added redirect to 404 controller in show_404() function. And for Google I added header("HTTP/1.1 404 Not Found"); and it's work perfect, and I can use now show_404() in any controller!
#5

[eluser]wiredesignz[/eluser]
You cannot 'redirect' to a different URL and then return the 404 header. You should return the 404 header from the invalid URL.
#6

[eluser]Mikle[/eluser]
[quote author="wiredesignz" date="1247762174"]You cannot 'redirect' to a different URL and then return the 404 header. You should return the 404 header from the invalid URL.[/quote]

Why?

My MY_Exceptions.php:
Code:
class MY_Exceptions extends CI_Exceptions
{
    public function __construct()
    {
        parent::__construct();
    }

    function show_404($page = '')
    {
        redirect('error_404','refresh');  // you can change this with what you want
        exit;
    }
}

And in error_404.php:
Code:
class Error_404 extends Controller {
    public function __construct(){
        parent::__construct();
    }

    public function index(){
        header("HTTP/1.1 404 Not Found");
        $this->load->view('error_404_main_tpl', NULL);
    }
}

It works ok!
#7

[eluser]CISCK[/eluser]
I think wiredesignz means that for SEO reasons, it is recommended that you use use the initial invalid URL and its 404 header. You may be "confusing" search engines by changing the URL / redirecting to another page and then declaring a 404 error. That said, I'm not an SEO expert, so you may want to look into this further.
#8

[eluser]kaola[/eluser]
.htaccess

ErrorDocument 404 /404.html
#9

[eluser]Dan Horrigan[/eluser]
Why go through all of this to show a 404 page when CI already does one? Simply modify the error_404.php file in the errors folder in the application folder. This is by far the easiest way to do it.
#10

[eluser]Mikle[/eluser]
My application has widgets and I use HMVC. I use main template with widgets and sitemap in content zone for 404 pages.




Theme © iAndrew 2016 - Forum software by © MyBB