O
O
Oval Enoc2019-09-30 22:28:56
Nginx
Oval Enoc, 2019-09-30 22:28:56

How to return different data for GET and POST requests in Nginx?

Hello.
I would be grateful if you could help me set up the config.

  • Return GET request from Android user-agent /java/index.java(one code, no execution)
  • On a GET request with any user-agent, remove/html/index.html
  • On POST request, pull back /php/index.php(with request processing in PHP)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2019-09-30
@ovalenko

http_rewrite_module and if directive :

if ($request_method = POST) {
    rewrite ^(.*)$  /php/index.php  break;
}

if ($http_user_agent ~ Android) {
    rewrite ^(.*)$  /java/index.java  break;
}

rewrite ^(.*)$ /html/index.html;

This is just a snippet of the config. There is no PHP processing, no static output - pictures, CSS, JS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question