Reputation: 4122
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.
Upvotes: 0
Views: 73
Reputation: 10898
What is the outcome of the re-write rule?
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 %1
will never be defined.
Picking up Alexander's description /letters{/letters}([/digits])
where the /digits
are optional. The repeat group is "zero or more letters" and hence will eat any /
characters, and these are greedy matches, so /aa/bb/cc/123
will 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.php
relative to the current path, which will probably be the DOCROOT, so unless DOCROOT/var/www/index.php
exists, this will result in a 404.
Upvotes: 2
Reputation: 32306
It is supposed to redirect all requests of the form /letters{/letters}[/digits]
to a local file var/www/SOMETHING/index.php
but it does not: first, there is no capturing group (all groups have leading ?:
and, consequently, it is not clear what SOMETHING
will be). Next, the var/www...
part should perhaps have a leading /
.
Upvotes: 2
Reputation: 11465
Following the mod-rewrite help, the %1
should refer to the first capturing group of the regexp from the last RewriteCond. But the regexp only has non-capturing groups...
Upvotes: 0