Support

Admin Tools

#32753 How to redirect to 403 custom page?

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by on Friday, 01 May 2020 17:17 CDT

mvasilescu
Hi Nicholas,

I try to add different rules via htaccess Maker ( Custom .htaccess rules at the top of the file - Field ) to redirect 403 errors to custom 403 Page instead 403 Server Page.

To black, the IP/IP Range I can duo in Admin Tools / Site IP Blacklist or in server CPanel / Security / Blocked IPs.

Can you tell me please what's the best rule to work in this case?

Thanks and stay safe.
Marius

nicholas
Akeeba Staff
Manager
If you want to redirect Joomla's 403 page to a custom error page – this is not possible. Apache's custom error pages (which are NOT redirections) only apply when the content of the HTTP response producing the HTTP error code is less than 512 bytes long. Joomla generates a full page which is significantly over than limit.

Also, I don't understand what this is referring to (probably because autocorrect on your browser corrupted your English beyond recognition):

To black, the IP/IP Range I can duo in Admin Tools / Site IP Blacklist or in server CPanel / Security / Blocked IPs

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

mvasilescu
If I use Joomla's .htaccess original file and add:
deny from 89.25.108.107
<Files 403-error.htm>
allow from all
</Files>
ErrorDocument 403 /403-error.html
... it's working perfect.

BUT, if I add the code via htaccess maker the code is not working.
The server admin tell me is because is some conflict in htaccess file due the other rules added by the htaccess maker.

Can you please advise what's the best rule to add via htaccess maker in order to work properly.

Thanks
Marius

nicholas
Akeeba Staff
Manager
This line is wrong and has no effect:
<Files 403-error.htm>

Therefore your solution is invalid to begin with. While you think that it's working "perfectly" it, in fact, does not work at all. The blocked IP address sees a 404 Not Found error. It should end with .html not .htm (since your error document is 403-error.html).

The second thing you are missing is that you are using the Frontend Protection of the .htaccess Maker. Therefore the 403-error.html file is inaccessible over the web. Go to Admin Tools, .htaccess Maker and find the "Allow direct access to these files" area. Add the following to a new line:
403-error.html

Click on Save & Create .htaccess. Now what you're trying to do will work.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

mvasilescu
Unfortunately, for some reason do not redirect the 403 error to specific page ( 403-error.html ), instead is showing ...

Forbidden
You don't have permission to access this resource.
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

And additional help will be really appreciated.

Thanks
Marius

nicholas
Akeeba Staff
Manager
Sorry for the delayed answer. Yesterday we had a power outage followed by an Internet outage. Service was restored last night, only for the power to go out, again, this morning. FINALLY I have both power and Internet.

I tried to reproduce your issue. I am using the .htaccess Maker like you do. I created a file named 403-error.htm (note that the extension .htm, NOT .html, .Htm, .Html, .HTM or .HTML – these are all different extensions and yes, case does matter).

In the .htaccess Maker I added the following to "Custom .htaccess rules at the top of the file":
ErrorDocument 403 /403-error.htm


I also added the following in a new line in the "Allow direct access to these files" area:
403-error.htm

Please note that the name, including the lowercase/uppercase letters of the filename and extension, match exactly the file on my site's root.

Trying to raise any kind of 403 error it works. I see the contents of my file instead of the default 403 error page. To make sure I am not mistaken I had my custom error page display "Baby did a bad, bad thing" (yes, that's Chris Isaak lyrics).

However, there is exactly one case where this doesn't work by itself (and I did test that it doesn't): when you are blocking access to an IP (e.g.with something like "deny from 111.222.333.444") AND you are trying to access a .php file. "Acces a .php files" also applies when you are trying to access a SEF URL on your site such as /foo/bar.html or index.php/foo/bar.html since this is a missing file which is redirected internally by Apache to your site's index.php (that's how SEF URLs work). Because of the way Apache works under the hood you do need to add the following to the "Custom .htaccess rules at the bottom of the file":
<Files "403-error.htm">
        Allow from all
</Files>


So, if you did follow my earlier advice to fix your code AND add the 403-error.html file to the "Allow direct access to these files" area your issue can no longer be reproduced. I can only assume that you missed one of the steps?

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

mvasilescu
I follow your instruction and the redirection was made to Joomla Error default page not to the 403-error.htm custom page.
Any thoughts?

Thanks and all the best to you all in this turbulent times.
Marius

nicholas
Akeeba Staff
Manager
The only thing I can think of is that you are confusing what Joomla reports as a 403 with an HTTP 403 error response coming from your server. This is apples and oranges.

You cannot have Joomla's 403 response display an Apache custom error page. These are error pages created by Joomla itself, using the error.php file of your site's template (or a fallback to templates/system/error.php if the template does not provide one). Apache error handling is NOT involved in this case. For example, if you try to access an article that's not public without being logged in Joomla generates a 403 response using its own error page. Same goes for when Admin Tools is blocking access. These pages are rendered by Joomla and you cannot redirect them to Apache's error pages.

When Apache itself throws a 403 error (e.g. you try to access something that's forbidden in .htaccess) then and only then will the custom HTML error file be used.

This applies with Joomla's default .htaccess file as well. So I am not sure why you're saying that this works with it. I've tested it and, predictably, it doesn't work for the reason I explained. Apache uses its custom error pages only when the error response has no content. Joomla always generates content for its error response, therefore its content is used instead of the custom error page.

If you are trying to customize Admin Tools' error page the method you're following is wrong. The documentation already tells you how to create a template override and which option to set in Admin Tools to create a custom error just for requests blocked by Admin Tools.

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

System Task
system
This ticket has been automatically closed. All tickets which have been inactive for a long time are automatically closed. If you believe that this ticket was closed in error, please contact us.

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!