2

How to make redirect to 404 or root page when user types query to not existing page and SSI include gets error?

Or how to check if HTML-document exist on server and if doesn't then also make redirect?

If user types domain.tld?anyquerystringon my site then it includes anyquerystring.html HTML-page by SSI.

If user types query of not existing page like domain.tld?blahblahblah then it gives the [an error occurred while processing this directive] in the place of SSI include.

andrew
  • 426
  • 8
  • 18
  • 1
    look at file_exists() http://uk.php.net/manual/en/function.file-exists.php – Waygood Aug 22 '12 at 09:14
  • 1
    Thought this was a querystring issue include($_GET['page']); But .htaccess -f (file not exist) and -d (directory not exist) with apache's mod_rewrite will do the trick – Waygood Aug 22 '12 at 09:20
  • Why are you talking about SSI in a question tagged PHP? Are you using PHP or SSI? What does JavaScript have to do with this? – Quentin Aug 22 '12 at 14:17
  • Because I don't what could help here from the start. – andrew Aug 22 '12 at 14:38

2 Answers2

2

There is no way to check it with php, because if a page does not exists how your php code can run, you need to make changes to .htaccess file as it will tell the server to a redirect a user to a defined page in case of 404

RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/404.php
Aman Virk
  • 3,909
  • 8
  • 40
  • 51
  • You didn't read the question. I'm not getting 404 I'm getting error in the place of SSI include that's included into another page. – andrew Aug 22 '12 at 10:32
0

You can configure error message in SSI. The answer is

<!--#config errmsg="Put here your error message, HTML or other code" -->
andrew
  • 426
  • 8
  • 18