9

A stupid question perhaps, but I can't seem to find good documentation or examples for this...

When you're using location blocks to filter incoming requests, do you do your rewrite from the matched location or from the start of the request?

An example:

location ^~ /category/ {
    rewrite ^/category/paid-search-news/?$ /tag/paid-search permanent; # this,
    rewrite ^paid-search-news/?$ /tag/paid-search permanent; # this,
    rewrite paid-search-news/?$ /tag/paid-search permanent; # or this?
}
mgorven
  • 30,615
  • 7
  • 79
  • 122
probablyup
  • 258
  • 1
  • 2
  • 5

2 Answers2

4

From the start of the request. There is documentation on that here.

location /download/ {
  rewrite  ^(/download/.*)/media/(.*)\..*$  $1/mp3/$2.mp3  break;
  rewrite  ^(/download/.*)/audio/(.*)\..*$  $1/mp3/$2.ra   break;
  return   403;
}
coredump
  • 12,713
  • 2
  • 36
  • 56
3

The documentation implies that the full URL is matched (i.e. your first example).

mgorven
  • 30,615
  • 7
  • 79
  • 122