A
A
Anton_from_Amber2013-07-26 21:58:35
MODX
Anton_from_Amber, 2013-07-26 21:58:35

How to leave unchanged URL for 404 page in MODx Evo, NGINX+phpFPM conditions?

I’m ready to sprinkle ashes on my head and admit that I’m a bad seeker, but I really can’t solve the problem and ask the community.
There is a site on MODx Evo. I want to make a human page with a 404 error. The main problem is to leave the address line reporting the missing target and give the opportunity to correct a typo or simply understand what went wrong.
The trick using javascript+HTML5 history didn't help. I didn't find the correct address.
Perhaps there is already a modification (plugin for example) for modex?
Perhaps this problem can be solved at the NGINX + phpFPM frontend level?
Please tell me how to proceed in this case.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton_from_Amber, 2013-07-29
@Anton_from_Amber

Figured out how to do it. I'll leave it for other sufferers.
The solution is far from elegant, but quite working.
We only edit modex.
In the root of the site (or wherever it is convenient for you), we place a text document that will be displayed in response to an error. I placed my placeholders in it for later replacement.
We create a plugin, the meaning of which is to intercept the 404 error and display the static file in the output.
It must be remembered that through the modex API it is impossible to simply calculate a chunk if it contains calls to other chunks, snippets and placeholders. However, with the proper level of detail, you can call the insertion of static chunks (for example, a footer), the results of certain snippets (for example, a menu or a news feed) in the plugin code.
In my case, I had a couple of static chunks and a placeholder for the wrong string I was looking for. As a result, the plugin code looks like this:

$basePath = $modx->config['base_path'];
$e = &$modx->Event;

switch ($e->name) {
  case 'OnPageNotFound' : {
    $out = file_get_contents("404.html");
    $rpl = 'http://my.domain.ua'.$_SERVER["REQUEST_URI"];
    $out = str_replace("{{ErrURL}}", $rpl, $out);
    $rpl=$modx->getChunk('metro_mnd');
    $out = str_replace("{{metro}}", $rpl, $out);
    $rpl=$modx->getChunk('footer_mnd');
    $out = str_replace("{{footer}}", $rpl, $out);
    echo $out;
    exit;
  }
}

G
George, 2013-07-27
@soloweb

Well, look, in the “try” rules, Nginx has the ability to intercept the request, it can be redirected anywhere you like, it can be a php script or a static page, or something else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question