views:

82

answers:

1

How would you create a regular expression that would parse the following url

http://example.com/answers/38-my-example-question-on-regular-expression

Specifically, "/answers/38-my-example-question-on-regular-expression" versus "/answers/category"

If the regex finds "38" a number, then it does this:

RewriteRule answers/([-_~*a-zA-Z0-9]+)(\/)?$ answers/view.php?title=$1&id=$2&%{QUERY_STRING}

else:

RewriteRule answers/([-_~*a-zA-Z0-9]+)(\/)?$ answers/categories.php?key=$1

I want to place the regex in the .httaccess for my webapp.

Thanks!

+1  A: 
RewriteRule answers/([0-9]+)-?([-~a-zA-Z0-9/]*)/?$ answers/view.php?title=$2&id=$1&%{QUERY_STRING}
RewriteRule answers/([-~a-zA-Z0-9]+)/?$ answers/categories.php?key=$1

The two expressions - one looks for one or more numbers followed by a potential - and more characters to make up the title. The other looks for anything else and calls it a category.

gnarf
Just tested this and works great! Thanks sooo much!!!
Ranknoodle