Apache URL rewrite UUID v1

我与影子孤独终老i 提交于 2020-07-22 05:56:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!