Mobile app version of vmapp.org
Login or Join
Bryan171

: Apache httpd.conf && .htaccess directives written in PCRE? I look at the directives syntax of Apache configuration files like httpd.conf && .htaccess and I must say it looks quite similar

@Bryan171

Posted in: #Apache #Htaccess #HttpdConf #RegularExpression

I look at the directives syntax of Apache configuration files like httpd.conf && .htaccess and I must say it looks quite similar to PCRE syntax (that stand for Perl Compatible Regular Expressions).

But, is the directives syntax really a Regular-expressions syntax ?

I am not quite familiar with regular expressions to strictly determine and thus aim the question to webmasters and/or programmers who have mastered or became experienced with it enough to answer.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Bryan171

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

it looks quite similar to PCRE syntax


Yes, many of the parameters to Apache directives do take regular expressions (regex) and the "flavour" of regex used is indeed PCRE.

This applies to mod_rewrite and in fact any other Apache module that uses regex.

There are some minor differences (and additions) in the syntax used by Apache, but this is primarily because there are no regex "delimiters" (commonly /) to mark the start and end of the regex, so slashes do not need to be (backslash) escaped.

Also, because spaces are used as delimiters in Apache directives, literal spaces must be backslash escaped in the regex itself. Or, the regex can be surrounded in double quotes.

And since there are no regex delimiters, there are no pattern modifiers, such as i (eg. /regex/i) for case-insensitive matches. Instead, there are flags in mod_rewrite, eg. NC (NOCASE) for case-insensitive matches.

In addition to the normal syntax, you can prefix the pattern with ! to negate the regex. This makes it trivial to make a truthy expression when something does not match. mod_rewrite also has an additional backreference for matching groups in the RewriteCond CondPattern ie. %1 as well .

With Apache 2.4 you now have Apache Expressions, this does put back delimiters and pattern modifiers.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme