Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here'sHere's my original SO post, for reference/context.

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here's my original SO post, for reference/context.

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here's my original SO post, for reference/context.

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

Post Reopened by Jamal
deleted 15 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here'sHere's my original SO post, for reference/context: http://stackoverflow.com/q/27406188/244826


UPDATE.

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here's my original SO post, for reference/context: http://stackoverflow.com/q/27406188/244826


UPDATE

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here's my original SO post, for reference/context.

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

Post Closed as "Needs details or clarity" by Jamal
added 725 characters in body
Source Link
Sonny
  • 153
  • 1
  • 6

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here's my original SO post, for reference/context: http://stackoverflow.com/q/27406188/244826


UPDATE

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here's my original SO post, for reference/context: http://stackoverflow.com/q/27406188/244826

I have two working configurations that, on the surface, seem to do the same thing. They both accomplish the functionality that I need:

location ~ ^/(css|images|js)/ {
    location ~ '^/(css|js)/[0-9]{8}-(.*)$' {
        alias /$1/$2;
    }
    root /server/path/to/web/root;
}

AND

location ~ ^/(css|images|js)/ {
    rewrite '^/(css|js)/[0-9]{8}-(.*)$' /$1/$2 break;
    root /server/path/to/web/root;
}

They both take a URL like /css/87654321-styles.css and deliver the file /css/styles.css. I lean toward the second solution because it's more succinct, but I don't know if one is better than the other for performance reasons, unintended side-effects, etc.

Here's my original SO post, for reference/context: http://stackoverflow.com/q/27406188/244826


UPDATE

After being directed to the documentation for the Nginx rewrite module, I found these interesting lines:

The ngx_http_rewrite_module module directives are processed in the following order:

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
  • a location is searched based on a request URI;
  • the directives of this module specified inside the found location are executed sequentially;
  • the loop is repeated if a request URI was rewritten, but not more than 10 times.

So, if I used the rewrite directive without the break flag, there could be at least one additional loop of the server level directive.

Added `break` flag to the rewrite rule
Source Link
Sonny
  • 153
  • 1
  • 6
Loading
Source Link
Sonny
  • 153
  • 1
  • 6
Loading