Nginx rewrite rule for CSS and JS files
I’ve been using for a while .htaccess in Apache and now, when using Nginx need to learn new writing.
I’ve been using in .htaccess:
RewriteRule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [L]
It rewrite ...css/style.1234567890.css to css/style.css.
Now, in Nginx I’m trying this:
location ~* \.(js|css)$ {
rewrite ^(.*)\.\d{10}\.(css|js)$ $1.$2 break;
}
or
location ~ ^(.*)\.\d{10}\.(css|js)$ {
rewrite ^(.*)\.\d{10}\.(css|js)$ $1.$2 break;
}
But after sudo nginx -t there is still unknown directive "10}\.(css|js)$" error.
What I’m doing wrong?
Read more here: Source link
