Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


How to write a rewrite rule with a string as the key?


I currently have an array of projects and for the key of each project I am using the project name instead of a number like 101. In the rewrite rule tutorials Randy only shows how to do this using numbers. What regular expression could I use to solve this?

Thanks in advance.

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Eric,

The most generic expression you can use is ([\w-_]+) which will make all characters in both upper and lowercase and allow hyphens and underscores if you need them, if you can let us know an example URL we can give you a more precise expression.

Ok cool, thanks Chris, I will give this a try! I am still working from my local server so it would be something like:


What I want is: