0

Tried searching in PCRE Documentation. Couldn't find anything.

What does & signify in PCRE?

Saw a usage of it in an expression like this:

(^|&)p=(about_us|contact)(&|$) [NC]

in this question: RewriteCond %{REQUEST_URI} : how to stop, if REQUEST_URI contains ?p=about or ?p=contact

I do know the meanings of ^, $ & |. as well as grouping.

Community
  • 1
  • 1
ThinkingMonkey
  • 12,539
  • 13
  • 57
  • 81

2 Answers2

3

It doesn't have any special meaning.

I imagine that the expression is simply trying to match either the start or end of the query string, or otherwise a literal & character on either end of the query string. Remember that & is typically used to separate query string parameters.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
-1
^ =the start of the phrase
$ = the end of the word
| = or operator (ab|bc) will accept both ab and bc
& doesnt have special meaning

grouping is used in order to use the values later (instead of just checking if the string matches) use can use the matches that you catched in a parenthesis.

RewriteRule ^(.*)$ index.php?r=$1

this will take the file that is being accesses and pass it as parameter r to the index.php file

the phrase you pasted is looking for 4 different situations. 1. p=... [as the whole qs] 2. the qs starts with p=...& but contains other parameters as well 3. &p=... - p is the last parameter 4. &p=...& - p is in the middle of the qs

Yaron U.
  • 7,681
  • 3
  • 31
  • 45