A
A
Alexander Gavva2012-05-23 13:52:39
Nginx
Alexander Gavva, 2012-05-23 13:52:39

Non-standard handling of 404 errors?

When migrating a project from nginx to apache, it became necessary to cleverly handle a 404 error.
Let me explain:
on nginx, the following redirect was present in nginx.conf:

#Приватный локейшен для отдачи файлов слоев Dojo. В случае если файл<br/>
 #слоя отсутствует. Заменяем код ответа с 404(файл не найден) на код<br/>
 #200 и перенаправляем на приватный локейшен для генерации пустого файла<br/>
 #слоя<br/>
 location ^~ /jsLayers/<br/>
 {<br/>
 internal;<br/>
 alias $serverRoot/resources/js/$jsCurrentFolder/layers/;<br/>
 error_page 404 =200 /emptyLayer.js;<br/>
 }

those. if any of the files is not found by mask, a specific file is returned and the response code is replaced by 200.
You can’t use the standard ErrorDocument, because for files in other folders the correct 404 should be returned, and plus in ErrorDocument we cannot change the response code to 200.
I look towards RewriteCond and RewriteRule followed by a redirect with code 200 (I don’t know if it’s correct), but I can’t find a variable that would be responsible for the server response code (to intercept it)
I don’t ask for a ready-made solution. I think if they just pointed out in which direction to dig, I would have found the answer myself.
I will be grateful for advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gregory, 2012-05-23
@aprel_co

Mod_Rewrite, in my opinion, is quite appropriate.
Use RewriteCond to check for the non-existence of the file (by mask, if there are several), and in RewriteRule just in this case redirect to /emptyLayer.js with code 200.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question