Skip to main content
1 of 5
Sonny
  • 153
  • 1
  • 6

Nginx Alias vs Rewrite

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;
    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

Sonny
  • 153
  • 1
  • 6