问题
How do you rewrite a 36 character v1 UUID precisely with maximal-checking using RewriteRule?
UUID() returns a value that conforms to UUID version 1 as described in RFC 4122. The value is a 128-bit number represented as a utf8 string of five hexadecimal numbers in aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee format:
Please give something better than this:
RewriteRule ^([A-z0-9\-]{36})$ index.php?uuid=$1 [L,QSA]
回答1:
You may try:
^[a-fA-F0-9]{8}-(?:[a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}$
Explanation of the above regex:
^, $
- Represents start and end of the line respectively.[a-fA-F0-9]{8}
- According to the docs; as a utf8 string of five hexadecimal numbers; so it is good to allow only hex characters. Therefore; first string before-
is 8 characters long hex value.(?:[a-fA-F0-9]{4}-){3}
- Represents a non-capturing group matching hex characters 4 times followed by a-
and the whole pattern repeats exactly 3 times.[a-fA-F0-9]{12}
- Represents hex characters exactly 12 times.$0
- For the matching part you may use 0th captured group since there is no special capturing.
Regex demo
来源:https://stackoverflow.com/questions/62776450/apache-url-rewrite-uuid-v1