Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The base URL determination is substantially faster if the input starts with the expected common substring (the initial match of the RewriteRule), rather than repeatedly recalculating the backreferences until the lengths match.
A demonstration that the updated version can take take two orders of magnitude fewer steps:
original: https://regex101.com/r/Lvi7Pu/1
updated: https://regex101.com/r/RXjdVZ/1
Also simplify previous rules where the match itself is not used in a condition or rewrite.
Description
Regexps are a performance drain when unoptimised, especially when they rely of heavy backtracking and re-checking for matches. PCRE has built-in features to optimise for un/greedy matching which The BASE env var determination was not using. This patch optimises both the logic and the operators to perform much faster matching.
My only concern is that it appears as though the original did not always rewrite to the
index.php
file, but surely that can't be true: https://regex101.com/r/Lvi7Pu/2I could modifiy this so that the rewritten path has only a relative prefix (except retain the
/
in the env var for backwards compat.), which makes more sense to me because rules are already matched against relative paths in.htaccess
context.