Jump to content

[SOLVED] redirect all wrong urls to index page


isaac_cm

Recommended Posts

You could make a custom 404 error page, set its location in your .htaccess file, and then put a redirect on that page . I do this on my website using javascript, because I like the user to know they had a 404 error. The redirect waits 10 or 15 seconds before redirecting, and that 10 or 15 seconds is counted down on screen. Try it, I think you'll like it.

so...why do you make your visitors sit around on the 404 screen that long?  personally, I hate it when websites do that. 

 

They can go anywhere they want. The 404 page has all of the normal menus of the site. It also has a link for them if they don't want to wait for the redirect.

I did it from cpanel and it work with firefox but not IE or chrome

 

the .htaccess is as follow

 

# Use PHP5 as default

AddHandler application/x-httpd-php5 .php

 

RemoveHandler .html .htm

AddType application/x-httpd-php .php .htm .html

 

I know that there is no ErrorDocument but there is file 404.shtml and it work !!

 

please advice

 

thanks

ErrorDocument 404 /index.htm

 

Or within any page

 

function redirect( $url ){
    if (! headers_sent( ) ){
    
        header( "Location: ".$url );
        exit( 0 );
    }
    echo "<script language=Javascript>document.location.href='".$url."';</script>";
    exit( 0 );
}

The htaccess option is the best

 

ErrorDocument 404 /index.htm

 

If your just using it to redirect wrong urls htaccess will do it for you, but if you really want to you can do it this way

 

ErrorDocument 404 /error.php

 

And in error.php

 

function redirect( $url ){
    if (! headers_sent( ) ){
   
        header( "Location: ".$url );
        exit( 0 );
    }
    echo "<script language=Javascript>document.location.href='".$url."';</script>";
    exit( 0 );
}

redirect("http://site.com/"); //redirect anywhere you want

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.