Custom 404 error page in cPanel is not working - apache

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?

Related

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

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.

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.

The requested URL was not found on this server

I have simple html site. how I can fix the problem 'The requested URL was not found on this server' when user gives wrong URL. for example user type mydomain.com/abc.html and this page is not exist on server, so it will cause an error. how to redirect it on error page to avoid this error.
Create a .htaccess file and add this line.
ErrorDocument 404 /foo.html
This will redirect any 404 error to foo.html

Apache directive returning some static content directly from configuration

I am looking for Apache httpd directive, that would immediately return some plaintext content ("System was not configured yet") or at least immediately generate 500 exception (so I can use ErrorDocument 500 'System was not configured yet').
Is there something I could use, or do I need to use some files on dics for this?
use this document :
The JK Connector is a web server component used to invisibly integrate Tomcat with a web server such as Apache or IIS. Communication between the web server and Tomcat is via the JK protocol (also known as the AJP protocol).
http://tomcat.apache.org/tomcat-4.1-doc/config/jk.html
Hope it can help you!
Edit:
you can also see this link:
http://www.viart.com/activating_friendly_urls.html.html
How to make a redirect to 404 custom page if fURLs are enabled
To make a redirect to a custom 404 page please do the following steps:
Login to your ViArt Shop Admin console.
Navigate to Administration > CMS > Custom Pages and create a 404 custom page
Click 'Update' to save the changes.
Access your site via any FTP client program and open your .htaccess file.
Insert the following string at the very beginning of the file:
ErrorDocument 404 /friendly_url.php
- Save the changes and upload the updated file to the root folder of your shop.
Open the file 'friendly_url.php' (located in the root folder) and find such a code:
$is_friendly_url = false;
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
exit;
-Replace this code with the following:
header("HTTP/1.0 200 OK");
header("Status: 200 OK");
set_get_param("page", '404');
include_once('page.php');
return;
where '404' is the name of your custom page as created in your ViArt shop Admin console.
Note: If you do not want to create a custom 404 page in your Admin panel please add the following code to your 'friendly_url.php' file:
$echo_string = implode("",file('http://example.com/404_text.txt'));
echo $echo_string;
exit;
where '404_text.txt' is any empty text file saved in the root folder of your shop.
Save the changes in the 'friendly_url.php' file and upload the updated file to the root folder of your shop.
Open your browser and type something like: http://example.com/404, where example.com equals your actual site URL and 404 is the name of your custom 404 page. If you did everything correctly you will see your 404 custom page.
Created a file for that plus error document setting for all possible URLs:
Alias /katello "/usr/share/katello/public/"
<Location /katello>
DirectoryIndex not_configured.txt
ErrorDocument 404 'Katello was not configured yet, please run katello-configure'
</Location>

notfound.html is not found

Pretty sure based on various examples (like the one here) I set things up correctly:
1) I created a file 'notfound.html' in the root directory of my site
2) I'm running xampp, ie. Apache web server, so based on the stuff I've read, Apache looks for a notfound.html in the root directory of a site when a non-existent page is typed in the browser, such as www.mysite.com/NotAValidPage.html and uses that notfound.html for the 404 error message
Here's what I've tried and the result of each attempt:
1test) I put my own notfound.html in my site's root directory and enter a non-existent page
1result) my notfound.html is not used, but instead the default 404 error from (I guess) my web server, appears and says:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try
again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
2/14/2012 9:11:29 AM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
2test) I next added an .htaccess file to the root folder of my site and added this line in this .htaccess file:
ErrorDocument 404 /notfound.html
then I typed a non-existent page into my browser.
2result) I still see a default 404 error page, not my notfound.html, only this time the default error page says:
Not Found
The requested URL /mysite.com/indsadfaex.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying
to use an ErrorDocument to handle the request.
3test) I then modified my .htaccess file by removing the '/' before the name of my custom 404 error page filename as follows:
ErrorDocument 404 notfound.html
3result) Now when I type my site name followed by a non-existent page, I no longer see the default 404 error page -- the browser window is completely blank except for the following at the top left corner:
notfound.html
Not sure what to do here, seems like I am missing some subtlety -- any ideas are really appreciated.
EDIT: I doubt it matters but there are 2 other statements in my .htaccess file for redirection situations:
RewriteEngine on
RewriteRule ^([^/\.]+)$ theHandlerPage.php?theArgumentPassedIn=$1 [L]
The regex here simply says 'go to the very end of the URL typed in and match a contiguous string of characters iff no '/' or '.' is in that contiguous stream of characters, then pass those in by way of $_GET[theArgumentPassedIn'] to the file theHandlerPage.php.
I don't think this rewrite rule is coming into play here because it will not match on a bad page name such as mysite/badpage.html because of the '.' in badpage.html.
Okay -- I discovered a bit of unexpectedness.
1) I move my notfound.html error file to the parent directory of my site -- whereas before the file was located at c:/xampp/htdocs/mysite/notfound.html, I have now moved this file to c:/xampp/htdocs/notfound.html.
2) then I use ErrorDocument 404 /notfound.html inside of my .htaccess file, which is located at c:/xampp/htdocs/mysite/.htaccess
And now when I type in the browser bar mysite/aBadfilename.html, my 404 notfound.html is showing up fine.
BUT THIS IS UNWORKABLE. I cannot have my notfound.html reside in the parent directory of my site, because I need a different notfound.html for each site I develop. I must be able to put my site's notfound.html in its folder space, ie. inside c:/xampp/htdocs/mysite.
Because c:/xampp/htdocs is the root folder of all web sites on the server.
Why is my web server looking for my-site's notfound.html in the c:/xampp/htdocs root directory instead of c:/xampp/htdocs/mysite? After all, I type mysite/badfile.html so the web server (in my opinion) should understand that notfound.html is in the c:/xampp/htdocs/mysite folder space.
Are you using Virtual Hosts ?
if so, i think there is a problem, open your httpd-vhosts.conf and look for a line where is DocumentRoot C:/xampp/htdocs/bla/blah/mysite/ and write down full path to a host, if it doesn't work play with Directory path. Hope it helps.