How to return a custom 404 Not Found page using FastAPI?

Update A more elegant solution would be to use a custom exception handler, passing the status code of the exception you would like to handle, as shown below: from fastapi.responses import RedirectResponse from fastapi.exceptions import HTTPException @app.exception_handler(404) async def not_found_exception_handler(request: Request, exc: HTTPException): return RedirectResponse(‘https://fastapi.tiangolo.com’) or, use the exception_handlers parameter of the FastAPI class like … Read more

404 header – HTTP 1.0 or 1.1?

In PHP you should probably use: header( $_SERVER[‘SERVER_PROTOCOL’].” 404 Not Found”, true ); or even better header( $_ENV[‘SERVER_PROTOCOL’].” 404 Not Found”, true ); (if supported) and thus leave it to the web-server which protocol to use. Actually, if you pass the status code as 3rd parameter, you can pass whatever you want in the 1st … Read more

how to fix 404 warnings for images during karma unit testing

That is because you need to configurate karma to load then serve them when requested 😉 In your karma.conf.js file you should already have defined files and/or patterns like : // list of files / patterns to load in the browser files : [ {pattern: ‘app/lib/angular.js’, watched: true, included: true, served: true}, {pattern: ‘app/lib/angular-*.js’, watched: … Read more

Is there a way to force apache to return 404 instead of 403?

RedirectMatch as in e.g. RedirectMatch 404 /\. does the trick, it prohibits access to all files or directories starting with a dot, giving a “404 Not Found” error. From the Apache manual: “The Redirect[Match] directive maps an old URL into a new one by asking the client to refetch the resource at the new location.” … Read more

Spring Java Config vs Jboss 7

I was using @SpringBootApplication As I read in this thread I needed to: Change the mapping of the DispatcherServlet to “/*” instead of “https://stackoverflow.com/” (by adding a @Bean of type ServletRegistrationBean with a servlet named “dispatcherServlet”) In this url I found the code solution: Add Servlet Mapping to dispatch servlet @SpringBootApplication public class Application extends … Read more

IIS7 custom 404 not showing

answer was to use <httpErrors existingResponse=”Replace” errorMode=”Custom”> <remove statusCode=”404″ subStatusCode=”-1″ /> <error statusCode=”404″ prefixLanguageFilePath=”” path=”/pages/404.aspx?he” responseMode=”ExecuteURL” /> </httpErrors> and not to have any system.web customErrors this worked for both .aspx and non .aspx requests. bizarrely this combination did not come up in any of the blog posts and stackoverflow answers I had investigated, it was … Read more