...

View Full Version : regex help for mod_rewrite



odealo
04-14-2011, 06:00 PM
ok, first of all I would like to say I'm a regex IDIOT!. That being said, here's what I got:

RewriteEngine On
RewriteRule ^/([^/\.]+)/deals/([^/\.]+)/?$ index.php?key=$1&permalink=$2



What I'm trying to do is match the following url request paths:

/key-goes-here/deals/permalink-goes-here
/key-goes-here/deals/permalink-goes-here/

The string will always start with /
The string may or may not end with /
The "key-goes-here" part will always be alphanumeric and - (hyphens to separate words)
The "permalink-goes-here" part will always be alphanumeric and - (hyphens to separate words)



Thanks in advance

ShaneC
04-15-2011, 05:15 PM
Try something like this:



^[A-Za-z0-9\-]+/deals/[A-Za-z0-9\-]+[/]?$


I highly recommend you look into REGEX. I avoided it for the longest time but it, truthfully, saves a lot of time and effort while programming to match user input. I found the following two things to be very helpful resources:

http://www.zytrax.com/tech/web/regex.htm
http://weitz.de/regex-coach/

Hope this helps!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum