I want to call a file by an url. If the url is not found then I want to show an error message instead of showing "The requested url is not found". How I will do this? Please help me.
Asked
Active
Viewed 274 times
0
-
1use a conditional statement and echo, or make a modification to your `.htaccess` file. Did you not research this first? – Funk Forty Niner Dec 30 '16 at 19:42
-
1Is there anything you've tried so far? – Rwd Dec 30 '16 at 19:45
-
1Possible duplicate of [.htaccess url-rewrite if file not exists](http://stackoverflow.com/questions/5469955/htaccess-url-rewrite-if-file-not-exists) – Funk Forty Niner Dec 30 '16 at 19:53
-
1You didn't put any effort in this whatsoever. – Funk Forty Niner Dec 30 '16 at 19:54
2 Answers
0
Create a .htaccess file in your web directory, and write the following:
ErrorDocument 404 /notfound.html
Make sure to replace notfound.html with your custom 404 html file.

Andrew Larsen
- 1,257
- 10
- 21
-
Question's that show no effort shouldn't be answered, IMHO and shared by many. – Funk Forty Niner Dec 30 '16 at 19:55
-
Thank you for your reply. I know that but it will not work for me because several user will use my extensions. so I have to fix it in code stage. if you have better solution in that stage then please let me know. – Adi Dec 31 '16 at 04:26
0
$headers=get_headers($url);
Then check if $result[0] contains 200 OK (which means the file is there)
A function to check if a URL works could be this:
function UR_exists($url)
{
$headers=get_headers($url);
return stripos($headers[0],"200 OK")?true:false;
}
/* You can test a URL like this (sample) */
if(UR_exists("https://www.example.com/"))
echo "This page exists";
else
echo "This page does not exist";
Hope this will help you out.

Glorfindel
- 21,988
- 13
- 81
- 109

bluezeal
- 1