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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 );
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.