Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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,650 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: