Faced with the fact that .htaccess ignored the L flag in the RewriteRule , resulting in a conflict of two rules. It was too lazy to figure out what was happening, and I decided to just change the regular rule for the first rule so that it never intersects with the second one. Actually, the rules:
Если запрашиваем /<имя файла>.js, то отдать файл /public/scripts/<имя файла>.js Если запрашиваем /lib/<имя файла>.js, то отдать файл /libs/js/<имя файла>.js Therefore, if the first rule does not process requests that begin with /lib/ , then the problem will disappear by itself. For example:
RewriteRule ^(?<!lib\/)((.*)(\.js))$ public/scripts/$1 [L] RewriteRule ^lib\/(.*)(\.js)$ libs/js/$1$2 [L] Past Apache in general does not know such a construction, not to mention the constant errors 500, which come out in the most unexpected places. But this rule works (discovered by chance, thanks to a typo):
RewriteRule ^lib\/(.*)(\.js)$ libs/js/$1$2 [L] RewriteRule ^(lib)?([^\/]*\.js)$ public/scripts/$2 [L] From the point of view of regulars known to me, the construction, at the beginning of the second rule, reads as "the beginning of a line may contain the substring lib ", but Apache clearly understands it somehow, because in this form the second rule no longer conflicts with the first. I tried to change their places, thinking that maybe the flag L could have just earned, but the order of these rules does not affect their behavior.
In connection with the above, I have a question: what is the general syntax of regular expressions that Apache uses (version 2.4.7, if that)? And where can I find complete documentation on it?
(?<!lib\/)is a preview block backward. The Apache documentation states that it supports PCRE regular expressions, in which the construct you specified is supported . Although you actually had to use the forward preview block,RewriteRule ^(?!lib/)(.*\.js)$ public/scripts/$1 [L]. The second example works only because[^\/]*finds 0+ characters other than/(everything with a slash will not be processed). - Wiktor StribiżewLflag is not ignored. If the rule worked with such a flag, then the further rules are not executed, BUT (if I'm not mistaken) if this rule has changed the request, then apache processes the .htaccess again from the very beginning. - Visman