Hello,

Is there a way to set up of custom html pages to replace the default pages that error throw?

I use htaccess to deny some IPs from members via FireWall. Every time these members access my site, they will receive an error.

However, I want to set up a custome page to replace the default pages that error throw.

How do I set such a default page for that error?

Thanks.

HAPPY NEW YEAR!

Dani AI

Generated

Short, practical follow-up to and : using your webserver’s error-page feature is the right approach, but there are a few common pitfalls to avoid and a couple of modern updates to apply. Point ErrorDocument (Apache) or error_page (Nginx) to a local path (not a full external URL) so the original HTTP status is preserved and crawlers don’t get redirected away from the real error code. (httpd.apache.org)

If you’re blocking IPs, don’t put your custom pages behind the same block. On modern Apache (2.4+) use the new Require syntax instead of the old Order/Allow/Deny logic; and put error pages in a small public folder or explicitly allow access to the file so banned clients still receive the custom page rather than a secondary 403. Example pattern for Apache 2.4 access control is shown below — adapt the IP and placement to your vhost or .htaccess. (httpd.apache.org)

<RequireAll>
  Require all granted
  Require not ip 125.126.127.128
</RequireAll>

If your error handler is a script (PHP/CGI), make sure it emits the correct HTTP status header so search engines don’t treat the page as a “soft 404.” In PHP you can call http_response_code(404) (or send HTTP/1.1 404 Not Found) before output. Test with curl (for example curl -I https://yoursite/nonexistent) and in Google Search Console — Google treats pages that show a “not found” message but return 200 as soft 404s. (php.net)

If you run Nginx or IIS: Nginx uses error_page + an internal location and needs proxy_intercept_errors / fastcgi_intercept_errors when sitting in front of a backend to catch upstream errors; IIS uses <httpErrors> or the UI to map status codes to files. Test end-to-end (curl + browser) and ensure the returned status code matches the error you want to signal. (nginx.org)

Member Avatar for Member #949455

Is there a way to set up of custom html pages to replace the default pages that error throw?

You mean these errors:

400 - Bad request
401 - Authorization Required
403 - Forbidden
404 - Wrong page
500 - Internal Server Error

If you don't know how to create a error pages you can read this:

http://www.hongkiat.com/blog/60-really-cool-and-creative-error-404-pages/

It will give you an idea on how to create one.

on the .htaccess file you need to add this (just an example):

DirectoryIndex index.php
ErrorDocument 400  /400.php 
ErrorDocument 401  /401.php 
ErrorDocument 403  /403.php 
ErrorDocument 404  /404.php 
ErrorDocument 500  /500.php 

Regarding about blocking (Deny) and allowing (Allow) it should look like this on your htaccess file (just an example):

#Deny List
order allow,deny
deny from 125.126.127.128 #specify a specific address
deny from 125.126.127.128/29 #specify a subnet range
deny from 125.126.* #specify an IP address wildcard
allow from all

#Allow List
order allow,deny
allow from 145.146.147.148 #specify a specific address
allow from 145.146.147.148/40 #specify a subnet range
allow from 145.146.* #specify an IP address wildcard
deny from all
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.