Forum Moderators: phranque

Message Too Old, No Replies

Allowing Optional Folder in Mod Rewrite

         

itledi

9:57 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



I'm trying to write a regex statement, but I'm running into difficulty:

What I originally had allowed the following:
/document/title/
/document/title2/
/document/title3
and so forth...

I want to allow all the previous, but also an optional folder, such as:
/document/1/title/
/document/2/title/
/document/2/title2/

Basically, I need to allow characters for a folder, but if there is something, then it is required to have a trailing slash.

What I had:
^document/([0-9a-z_-]+)/?$

What I'm working on:
^document/[([0-9a-z_-]+)/]?([0-9a-z_-]+)/?$

What I have doesn’t seem to work. Any help would be appreciated.

Also, I am passing those folder and title names to a variable in the rewritten url, so I need to keep the parenthesis.

jdMorgan

10:19 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have a bad pattern with a nesting problem.

pattern: [([0-9a-z_-]+)/]?
meaning: Match one or more characters, any one of (, [, 0-9, a-z, _, or -", followed by a ")" a "/" and an optional "]".

I suspect you wanted:


^document/(([0-9a-z_\-]+)/)?([0-9a-z_-]+)/?$

Now use $2 and $3 as the back-references to the parenthesized values.

Jim