Apache mod-rewrite: Can I have different rules for POST and GET requests?

I have a rewrite rule that looks like this:

RewriteRule ^foo/bar/([\w]+)/files/([\S\s]+)$ /mydirectory/$1/$2

I would like GET requests to go to / mydirectory / $ 1 / $ 2, and POST requests to be somewhere different. Is this possible with mod-rewrite?

+3
source share
2 answers

yes - use the THE_REQUEST variable. See documents

+5
source

Fine! Thanks, SB.

Here is what I did for reference:

RewriteCond %{THE_REQUEST} GET
RewriteRule ^foo/bar([\w]+)/files/([\S\s]+)$ /mydirectory/$1/$2

RewriteCond %{THE_REQUEST} POST
RewriteRule ^foo/bar/([\w]+)/files/([\S\s]+)$ /somewherelse/$1/$2

This redirects POST to "someelse" and GET to "mydirectory".

+2
source

Source: https://habr.com/ru/post/1773844/


All Articles