In the following code, what does the regex do?
RewriteCond %{REQUEST_URI} ^/(?:[A-Za-z]+(?:/[A-Za-z]*)*)(?:/\d+)?$
RewriteRule .* var/www/%1/index.php [L]
What is the outcome of the re-wrtie rule?
Thanks, I am helping a friend fix an old CMS and I don’t know why whomever made it did this.
AFAIK it will generate 404s when you don’t expect it to. Why?
The (?: something) brackets are basically the same as () except that they don’t set a match variable. Since all bracketing is like this
%1will never be defined.Picking up Alexander’s description
/letters{/letters}([/digits])where the/digitsare optional. The repeat group is “zero or more letters” and hence will eat any/characters, and these are greedy matches, so/aa/bb/cc/123will be parsed as (/aa)(/bb)(/cc)(/)(123). This will fail since 123 does not match(?:/\d+)?So it will only match alpha path strings, e.g. /aaa/bbb/ccc and %1 will be “” and in these circumstances this will redirect to
var/www//index.phprelative to the current path, which will probably be the DOCROOT, so unlessDOCROOT/var/www/index.phpexists, this will result in a 404.