wemustdesign Posted September 4, 2010 Share Posted September 4, 2010 At the moment when a user goes to a non existant or old page such as index.php?x=sample they are automactially directed to the homepage. How can I redirect these to a custom 'page not found page' in the .htaccess? Quote Link to comment Share on other sites More sharing options...
cags Posted September 4, 2010 Share Posted September 4, 2010 ErrorDocument 404 /404.html Obviously /404.html is the path to the file you wish to display. Quote Link to comment Share on other sites More sharing options...
wemustdesign Posted September 4, 2010 Author Share Posted September 4, 2010 But how do I get redirect the user to this when a page is not found rather than it automatically redirecting to the homepage? Quote Link to comment Share on other sites More sharing options...
PradeepKr Posted September 4, 2010 Share Posted September 4, 2010 Put this in your .htaccess file (of course create your custom page and name it "my-401-page.php") ErrorDocument 401 /my-401-page.php Quote Link to comment Share on other sites More sharing options...
cags Posted September 4, 2010 Share Posted September 4, 2010 I guess I don't understand the question. That's exactly what the 'code' I provided does. If Apache see's a page isn't found then it will automatically redirect to that page, that's the whole point of the directive. If you are trying to say that a page does exist, but you are deciding in a PHP script that some content doesn't exist (i.e. vanity URLs and a user that doesn't exist) then you can just use a header('Location: /404.html'); but that isn't a page not found or mod_rewrite related question. @PradeepKr 401 is an unauthorised error message, it has nothing to do with page not found. Quote Link to comment 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.