Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite question

         

utahgolfer

3:01 pm on Nov 18, 2008 (gmt 0)

10+ Year Member



Hi i need some help with reading a URI from right to left.

for example how can i grab only the last two directories

1/2/3/4/ are directories and i want to read only 3/4/. So only grab the last 2 directories no matter how many previous directories there are, and rewrite on those two values.

Any help would be appreciated.

g1smd

5:04 pm on Nov 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Something like
[b]/[/b]([^/]+)[b]/[/b]([^/]+)[b]$[/b]
or this
[b]/[/b]([^/]+)[b]/[/b]([^/]+)[b]/$[/b]
would likely be a starting point.

It is end-anchored, but not start anchored.

I am guessing it is quite inefficient.

It doesn't work if there are less than three items (because leading / isn't shown to RewriteRule in .htaccess).

You'd need another rule with a start anchor to test for that particular case; like

[b]^[/b]([^/]+)[b]/[/b]([^/]+)[b]$[/b]
or this
[b]^[/b]([^/]+)[b]/[/b]([^/]+)[b]/$[/b]

I suspect that jd probably has a better idea. :-)