Jump to content

error 404


Naughty

Recommended Posts

If I enter in the browser "http://my_address/page.html" and "page.html" is not exist, I will get "File .....\page.html not found."

How do I handle this event and to redirect the browser to an existing page "error404.html" or open "http://my_address"

 

Если я ввожу в браузере "http://my_address/page.html" и "page.html" не существует, я получу "File .....\page.html not found". Как мне обработать это событие и перенаправить браузер на существующую страницу "error404.html” или открыть "http://my_address"

Link to comment
Share on other sites

404 it's a generic error that webservers send when file page not found.

 

using IIS you can personalize your own error page message.

 

But if your are not using IIS, you need know that unigui use a indy's http server modified version.

 

for doing this, simplest solution is modify the \UniGUI\uIndy\uIdCustomHTTPServer.pas, catch the error after FOnCommandGet event, and put your html code or load it from file.

 

it's not best elegant solution, but it works !

 

procedure TIdCustomHTTPServer.DoCommandGet(AContext: TIdContext;
 ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
 if Assigned(FOnCommandGet) then begin
   FOnCommandGet(AContext, ARequestInfo, AResponseInfo);
   if AResponseInfo.ResponseNo=404 then
     AResponseInfo.ContentText:='PUT YOUR HTML CODE HERE';
 end;
end;

Link to comment
Share on other sites

404 it's a generic error that webservers send when file page not found.

 

using IIS you can personalize your own error page message.

 

But if your are not using IIS, you need know that unigui use a indy's http server modified version.

 

for doing this, simplest solution is modify the \UniGUI\uIndy\uIdCustomHTTPServer.pas, catch the error after FOnCommandGet event, and put your html code or load it from file.

 

it's not best elegant solution, but it works !

 

procedure TIdCustomHTTPServer.DoCommandGet(AContext: TIdContext;
 ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
 if Assigned(FOnCommandGet) then begin
   FOnCommandGet(AContext, ARequestInfo, AResponseInfo);
   if AResponseInfo.ResponseNo=404 then
     AResponseInfo.ContentText:='PUT YOUR HTML CODE HERE';
 end;
end;

 

 

AResponseInfo.ContentText:='<meta http-equiv="Refresh" content="0; URL=....">';

Thank you!

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...