OpenCart maintenance mode 503 error - apache

I install directadmin with CB2 + Apache + MariaDB 10.1.31 + PHP 5.6.34.
When I upload OpenCart and enable maintenance mode, Apache shows the 503 error page instead of maintenance.tpl.
I checked the catalog/controller/common/maintenance.php and found the following code:
if ($this->request->server['SERVER_PROTOCOL'] == 'HTTP/1.1') {
$this->response->addHeader('HTTP/1.1 503 Service Unavailable');
} else {
$this->response->addHeader('HTTP/1.0 503 Service Unavailable');
}
$this->response->addHeader('Retry-After: 3600');
I think the problem is that Apache does not handle the 503 Header correctly. When I change the web server to LiteSpeed, it is ok.
To check you can compare these two versions of the site. Both of them have the maintenance mode enabled, but:
The first is OK - http://takjens.com/
The second is not - http://server3.lammer.ir/
Please let me know how to fix this problem.

Here LiteSpeed has custom error page configured, while Apache shows default 503 error page, as defined in the response header.
To make Apache display the custom error page, do the following:
Add the custom error page directive to the Apache configuration or into the .htaccess file for the domain. Specify the path to the maintenance.tpl file relatively to the configured ServerRoot:
ErrorDocument 503 /path/to/maintenance.tpl
.tpl file extension is not something that Apache can serve by default. I order to process it properly, the correct file type should be specified for this extension either in Apache configuration or via .htaccess file:
AddType text/html tpl

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.

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.

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>

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.