Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite escape help

mod rewrite escape help

         

csdesign

10:59 pm on Jan 26, 2009 (gmt 0)

10+ Year Member



can someone please help me how to achieve this - i'm trying to get a this url to work but i can't seem to get around the htaccess special character, where would i apply "\" to escape the special character? the special characters are in the database so it could have ".", "/", "+".

www.example.com/items/var1/var2/var3/123-ABC-47.7

above url will not work with current mod rewrite below:

RewriteRule ^items/([A-Za-z0-9-]+)/?$ item.php?var1=$1 [NC,NS,L]
RewriteRule ^items/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ item.php?var1=$1&var2=$2 [NC,NS,L]
RewriteRule ^items/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ item.php?var1=$1&var2=$2&var3=$3 [NC,NS,L]
RewriteRule ^items/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ item_detail.php?itemid=$4 [NC,NS,L]

thanks

[edited by: jdMorgan at 4:16 am (utc) on Jan. 27, 2009]
[edit reason] example.com [/edit]

Caterham

11:24 pm on Jan 26, 2009 (gmt 0)

10+ Year Member



i.e. you're looking for
[a-z0-9\-.,/+]

as your character class. The NC flag compiles the regEx case-intensive, so you don't need to specify the upper-case A-Z. The hyphen is a spacial character in a character class, hence it needs escaping (there are special cases where you don't need to escape the hyphen, e.g. at the beginning or end, and in between depending upon the other characters around).

csdesign

3:43 am on Jan 27, 2009 (gmt 0)

10+ Year Member



thank you, that did exactly what i wanted to do.