location ~ \startscript.js$ {
In regex the \s
at the start of your uri is a shorthand character class that matches a single space (or "whitespace character"). So this is unlikely to have matched anything. However, you should backslash escape the literal dot before the file extension.
I assume "file" in file.js
could be any file, it's not always "startscript"?
Try the following instead (UPDATED):
server {
location ~ \.js$ {
rewrite (.+)\.(\d+)\.js$ $1.js.php?c=$2 last;
}
}
However, as I mentioned in comments, this makes no difference with regards to SEO (search engines handle the query string just fine - always have). In the past, it was possibly a usability issue, as some proxy servers did not cache based on the query string - so users might not have seen the correct content (if they were behind a proxy that behaved this way) - but this is historical AFAIK.
See also my answer to the following question:
... this is throwing 404 error, Eg: domain.com/startscript.82b4527379bd2540f79f532950c7b96b.js
The above example specifically matches digits only (as in your initial example). What you have there looks like a 32 char hex value (hash?). Try the following instead (UPDATED):
rewrite "(.+)\.([\da-f]{32})\.js$" $1.js.php?c=$2 last;
Or use the the more generic \w+
, as @devnull suggested in comments, to match any "word" character (ie. 0-9
, a-z
, A-Z
and _
). Although with regex, it's generally advisable to be as specific as possible, so if it's always a 32 char hex then match a 32 char hex.