Forum Moderators: phranque

Message Too Old, No Replies

.htaccess mod_rewrite question

Have ([0-9A-Za-z]+) - Need to add special char.

         

wfernley

2:50 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone.

I need to update my .htaccess file. Currently I have this ([0-9A-Za-z]+) in one of my lines for looking for a filename (ex. index.html) but some of my files have -'s in them (ex product-index.html). I was curious what I need to add to that snippet to allow -'s to be included. I guess it would be considered a special character.

Thanks :)

Wes

dnps

3:23 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Tried this? ([0-9A-Za-z-]+)
- is not a special charcter

wfernley

6:05 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the reply dnps.

Unfortunately it didn't work though.

jdMorgan

6:54 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try preceding it with a backslash.

Alternately, use a negative match. Instead of looking for characters which are part of the field, look for the character that denotes the end of the field. Let's say your URL is

/articles/jun-2005-summer/page2

You could use articles/([A-Za-z-0-9\-]+)/(.*) or you could use articles/([^/]+)/(.*). The first subexpression of the latter pattern would match any character between the first and second slashes.

If you do decide to stick with [A-Za-z0-9], then look into using the [NC] flag, which will reduce the needed pattern to [a-z0-9].

Jim