bambinou1980 Posted November 11, 2015 Share Posted November 11, 2015 Hello, I am developing my first php script, I have a problem with the "not found" folders on the website. Let's say I the user goes here: http://mysite.com/folder1 but there are not folders there. At the moment I have this showing: Object not found!The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again. If you think this is a server error, please contact the webmaster. With the htaccess, how can I reroute the user to let's say the index page of the website please? Thank you, Quote Link to comment https://forums.phpfreaks.com/topic/299442-how-to-redirect-users-when-no-files-are-found/ Share on other sites More sharing options...
Ch0cu3r Posted November 11, 2015 Share Posted November 11, 2015 Use Apache's ErrorDocument directive? http://httpd.apache.org/docs/2.4/mod/core.html#errordocument https://httpd.apache.org/docs/2.4/custom-error.html Quote Link to comment https://forums.phpfreaks.com/topic/299442-how-to-redirect-users-when-no-files-are-found/#findComment-1526208 Share on other sites More sharing options...
bambinou1980 Posted November 11, 2015 Author Share Posted November 11, 2015 Thank you for the documentation but unfortunately I am getting lost into it... How would you simply tell the whole public_html folder that if there is a not found folder or file, redirect the user to the website root please? I found this code online, would this be ok: RewriteEngine onRewriteCond %{DOCUMENT_ROOT}/clients/$1/$2 !-fRewriteCond %{DOCUMENT_ROOT}/clients/$1/$2 !-dRewriteRule ^clients/([^/]+)/(.*)$ $2 [L] Thank you, Quote Link to comment https://forums.phpfreaks.com/topic/299442-how-to-redirect-users-when-no-files-are-found/#findComment-1526221 Share on other sites More sharing options...
Jacques1 Posted November 11, 2015 Share Posted November 11, 2015 Silently redirecting the user whenever they try to access a nonexistent resource is extremely confusing, especially for automated clients. There's a good reason why we have error codes like 404. When a resource doesn't exist, the client should know. Quote Link to comment https://forums.phpfreaks.com/topic/299442-how-to-redirect-users-when-no-files-are-found/#findComment-1526222 Share on other sites More sharing options...
ginerjm Posted November 11, 2015 Share Posted November 11, 2015 Instead of apache, why not use php to first check for the file or folder and if it exists issue a header call to it, and if not put out a polite message. OTOH - why do you have users typing in their own urls in the hopes that they make a hit somewhere? Why not give them a drop down of the available folders/files and let them choose a correct one? Quote Link to comment https://forums.phpfreaks.com/topic/299442-how-to-redirect-users-when-no-files-are-found/#findComment-1526223 Share on other sites More sharing options...
bambinou1980 Posted November 11, 2015 Author Share Posted November 11, 2015 Thank you for your reply. No the reason I was asking is because frameworks have a nice little routing script that do not allow people with the wrong access to go on a url. I have coded the app with permission on the landing pages yes but was wondering how do framework stop people typing urls (to pass parameters). Thank you, Quote Link to comment https://forums.phpfreaks.com/topic/299442-how-to-redirect-users-when-no-files-are-found/#findComment-1526224 Share on other sites More sharing options...
ginerjm Posted November 11, 2015 Share Posted November 11, 2015 You are saying you are concerned about passing parms but your previous examples only referred to files and folder names not in existence. BIG difference. Quote Link to comment https://forums.phpfreaks.com/topic/299442-how-to-redirect-users-when-no-files-are-found/#findComment-1526232 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.