How to show custom 404 error page when using `AllowEncodedSlashes On` - apache

I recently came across the AllowEncodedSlashes Apache directive:
https://intranet.csc.liv.ac.uk/manual/mod/core.html#AllowEncodedSlashes
If I hit a URL like this: www.domain.com/my/page/%2F/etcetera, Apache shows its default 404 error page:
However, I would like to return a custom 404 error page but how can I do it within my .htaccess? This doesn't work:
ErrorDocument 404 /entrypoint.php
I know I can do it if I have access to the server's httpd.conf configuration file (I tested locally). But what if I do not have access to the configuration on a remote site? Is there a way?
Thank you for the attention.

Related

Custom 404 error page in cPanel is not working

I've added a custom 404 page in cpanel - Advanced - Error Pages. And a file with the name 404.shtml is in the root of my website now. In the .htaccess I've added: ErrorDocument 404 /404.shtml (ErrorDocument 404 /public_html/404.shtml (direct path) also does not do the trick)
And if I call the file direct by going to https://.example.com/404.shtml it is showing. But when I type a page that is not existing, I still get the default Apache Not Found page.
Any clue what I am missing here?

local URL for apache ErrorDocument directive not working in .htaccess file

I want to use local URL (relative path) to show my custom 404 error message and it doesn't seem to be working as expected. As apache documentation stated here :
The syntax of the ErrorDocument directive is:
ErrorDocument <3-digit-code> <action>
where the action will be treated as:
A local URL to redirect to (if the action begins with a "/").
An external URL to redirect to (if the action is a valid URL).
Text to be displayed (if none of the above). The text must be wrapped in quotes (") if it consists of more than one word.
Methods 2 and 3 are working correctly. For testing purpose imagine a folder named test with 3 files.
index.php: main page
404.php: a custom 404 page
.htaccess:
RewriteEngine On
ErrorDocument 404 /404.php
Now accessing this URL http://localhost/test/blah-blah does not show my 404.php page instead a default Not Found page is displayed with this message:
The requested URL /tests/test-htaccess/asdasd was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an
ErrorDocument to handle the request.
Any idea how to fix this?
You probably found the solution to your problem since the time you asked, but for anyone having the same kind of issue, I would say the problem is that you are running your site with localhost.
The message says that Apache encountered a 404 error when trying to get the file specified for Errordocument 404, so it doesn't see
/404.php
I suggest you create a fake domain in your hosts file and set up a vhost with it.
Hosts on OSX :
sudo nano /etc/hosts
Hosts on Windows, Right-click this file to edit in administrator mode :
C:\WINDOWS\System32\Drivers\Etc\Hosts
and enter something like this:
127.0.0.1 myfakedomain.com
To set up virtual hosts, you must uncomment the call to httpd-vhosts.conf in httpd.conf (near the end, using MAMP in this case)
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
but the location of this file depends of the stack you are using (Wamp, Mamp, Xampp, etc) so search with the keyword "Virtual host" in its documentation.
Then you will be able to run your site using
myfakedomain.com/
in your browser and 404 errors should be handled the right way.

Redirect to external site on 500 error with .htaccess

I am working on a website (scratchyone.com). I need to have my .htaccess redirect to an external page
http://scratchywon.github.io/scratchyone.com/errors/500.html
on a 500 error. I am forcing a 500 with php.
http://scratchyone.com/500/
Here is my current code:
ErrorDocument 500 http://scratchywon.github.io/scratchyone.com/errors/500.html
EDIT: ErrorDocument 404 http://scratchywon.github.io/scratchyone.com/errors/500.html works
Now that I am using php to send the 500 error, the page doesn't display. It just displays the browser's default "500: Could not display"
Internal error in .htaccess not relay custom ErrorDocument (!) and simulate 500 error via PHP is not quite possible - when your script run it's too late - error document redirection is handled by apache mod_core (!) and PHP only send status.
So I think you can forget about PHP 500-simulation.
Try to make a directory next to main .htaccess and inside make faulty .htaccess
Or maybe this will be helpful for you:
https://www.digitalocean.com/community/tutorials/how-to-configure-apache-to-use-custom-error-pages-on-ubuntu-14-04
Section about 500 provide information how to simulate this error via bad proxy.

.htaccess forcing error pages on SSL

I have the following piece of code in my .htaccess file to force redirecting to custom error pages:
ErrorDocument 404 /ErrorPages/404.php
ErrorDocument 403 /ErrorPages/403.php
ErrorDocument 400 /ErrorPages/generalError.php
ErrorDocument 401 /ErrorPages/generalError.php
ErrorDocument 500 /ErrorPages/generalError.php
Everything works fine on port 80, but when it comes to SSL, the standard error pages are shown.
To be more specific:
http:www.mydomain.com/NoExistingPage.php redirects to the custom error page
https:www.mydomain.com/NoExistingPage.php DOES NOT redirect to the custom error page
am I missing something here?
Thanks in advance
Try putting a duplicate .htaccess file in the /secured folder and see if that works. The vhost for the https daemon is probably using /secured as doc_root which means even if the .htaccess from the regular doc_root is below the secured folder it will be ignored.

stop apache injecting it's own 404 not found page to the custom 404 error page

I'm having a problem implementing custom 404 error pages. my setup is a front-end apache 2.2.6 proxy request other than static file to the backend app server(apache 1.3.36)
i send 404 header back along with error page when user request a non-existing page to the backend server. I do get the error page back but somehow the backend apache server injects its own 404 not found page in the error page as well.
here is what injected to the not found page by apache:
Not Found
The requested URL /product/8jd4776 was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.36 Server at www.example.com Port 8888
any idea why this is happening?
set "ProxyErrorOverride On" with ErrorDocument in the front-end apache server solve the problem.
The content length of your custom 404 message must be 512 bytes or more.