1

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

AD7six
  • 63,116
  • 12
  • 91
  • 123
Martha
  • 31
  • 5
  • I added more examples. I need to restrict for /item/snv etc..not for pages – Martha Jul 13 '22 at 10:23
  • I am using memberpress on wordpress to restrict content to subscribers. Some pages ex: /snv00001-indice-di-documenti/ should not be available if not subscribed – Martha Jul 13 '22 at 10:28

1 Answers1

0

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

AD7six
  • 63,116
  • 12
  • 91
  • 123