isaac_cm Posted October 8, 2009 Share Posted October 8, 2009 hello, how I can redirect all wrong urls from visitors to index page ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/ Share on other sites More sharing options...
sKunKbad Posted October 8, 2009 Share Posted October 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-932777 Share on other sites More sharing options...
.josh Posted October 8, 2009 Share Posted October 8, 2009 so...why do you make your visitors sit around on the 404 screen that long? personally, I hate it when websites do that. Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-932784 Share on other sites More sharing options...
isaac_cm Posted October 8, 2009 Author Share Posted October 8, 2009 can you give me some code , but I need the redirect to be instant thanks Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-932785 Share on other sites More sharing options...
ldb358 Posted October 8, 2009 Share Posted October 8, 2009 put this in your .htaccess file ErrorDocument 404 404page.html Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-932794 Share on other sites More sharing options...
sKunKbad Posted October 8, 2009 Share Posted October 8, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-932866 Share on other sites More sharing options...
isaac_cm Posted October 8, 2009 Author Share Posted October 8, 2009 Many thanks , I appreciate all help Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-932920 Share on other sites More sharing options...
isaac_cm Posted October 8, 2009 Author Share Posted October 8, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-933361 Share on other sites More sharing options...
dreamwest Posted October 8, 2009 Share Posted October 8, 2009 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 ); } Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-933373 Share on other sites More sharing options...
isaac_cm Posted October 9, 2009 Author Share Posted October 9, 2009 the function redirect work but what make it called when the user type wrong url ? many thanks Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-933473 Share on other sites More sharing options...
dreamwest Posted October 9, 2009 Share Posted October 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-933587 Share on other sites More sharing options...
isaac_cm Posted October 9, 2009 Author Share Posted October 9, 2009 10/10 ! many thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/176909-solved-redirect-all-wrong-urls-to-index-page/#findComment-933693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.