Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6925935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:51:14+00:00 2026-05-27T10:51:14+00:00

I am using .htaccess to show custom HTML page for errors (401, 404, 500

  • 0

I am using .htaccess to show custom HTML page for errors (401, 404, 500 .. etc). I want to restrict direct access to the errors folder which contains the html pages. Inside of the .htaccess file of the errors folder, I have the following:

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com
RewriteRule \.(html|htm)$ - [F] 

This does not really seem to work and I get:

a 500 Internal Server Error error was encountered while trying to use an 
ErrorDocument to handle the request.

What changes do I have to make to the .htaccess file to get this to work. I am also wondering if it would work if I stick the errors folder outside of the public_html folder?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:51:14+00:00Added an answer on May 27, 2026 at 10:51 am

    In your .htaccess file, redirect all errors to one php file

    ErrorDocument 403 /errors.php
    ErrorDocument 404 /errors.php
    ErrorDocument 500 /errors.php
    

    in errors.php use $_SERVER[‘REDIRECT_STATUS’] with an if else statement to detect the errors and show custom messages

    if($_SERVER['REDIRECT_STATUS'] == 403)
    {
        die("Forbidden");
    }
    else if($_SERVER['REDIRECT_STATUS'] == 404)
    {
        die("NOT FOUND");
    }
    else if($_SERVER['REDIRECT_STATUS'] == 500)
    {
        die("Server Error");
    }
    else if($_SERVER['REDIRECT_STATUS'] == 200)
    {
     // user is trying to directly access the errors page, redirect to index.php
     header("Location: index.php");
    }
    else
    {
        // all other error codes
    }
    

    Here is a List of HTTP status codes. Write an else if statement for each error you want to detect. Undetected errors will fall in the else block

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using htaccess I'm basically trying to forbid access to the page i.e http://example.com ,
I want to, using htaccess, allow hotlinking BUT if someone views an image on
Is there some way to block access from a referrer using a .htaccess file
Is it possible using .htaccess or other apache powers to set a custom server
Am using .htaccess to create custom error pages, but the thing is that, it
On a standard LAMP application i am sending people to my 404 page using
We have in a htaccess file: ErrorDocument 404 /404.shtml Which works to show the
I'm using .htaccess and mod_rewrite to point to files that reside behind the DocumentRoot.
I'm trying to implement a solution using .htaccess and wildcard subdomains so that http://subdomain.example.com
I am trying to rewrite a URL using .htaccess. I am running on Apache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.