I would like to restrict access to my site using a custom URI regular expression.
I would like to allow access for such URIs:
https://example.com/item/page/2/?wpv_view_count=258
https://example.com/item/page/3/?wpv_view_count=258
and restrict content for such URIs:
https://example.com/item/snv00001-indice-di-documenti/
https://example.com/item/sa00068-libro/
https://example.com/item/aud00068-audio/
I need to provide the restrict content URI regex
CodePudding user response:
Based on the info in the question you want to match everything except requests which start with /item/page/
so:
/item/(?!page/).
That is:
/item/ # literal string
(?! # Begin negative lookahead
page/ # literal string
) # End negative lookahead
. # 1 or more characters
A negative lookahead is a zero-length match - so the next bit of the regex .
continues right after /item/
.
Here's a demonstration: https://regex101.com/r/8T2ytg/1