Learning and practicing rewrite rules and code

For a while I have been interested in learning more about URL rewriting.  I don't mind if I have to focus on how it would be done on an Apache server so I can narrow it to this if it matters.  Even more than learning I would like practical suggestions or methods on how to practice the rewrites.  Ideally short of setting up some server and a ton of files with real layout, etc.  Is there some way to do it virtually?  In other words provide a rule to a "htaccess" file and see how "pages" I set up would appear in the browser and the server work.  Basically I could easily set up the "framework" of the server and then test my rules and rewrites for the results.

I have had no luck finding something like this so maybe it is more complicated than I imagine.  However it seems like it wouldn't be too hard to virtualize and so I am hoping there is just some secret the rewrite experts here now. :)

Let me know if there is a question about this.  I am not really interested in suggestions to learn as much as ways to test and prove what I learn or think.  I will reward comments that provide good resources for learning but that would just be a bonus.  I have found some great info on that online and I already have some of the foundation I believe I need to do this well.  It is just frustrating to not have the opportunity to easily use and test it.

LVL 54
b0lsc0ttIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
To start learning URL rewriting with Apache, there's two things you need to know:

1) mod_rewrite (http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html)  Read through the documentation, and make sure you visit the "See Also" links found at http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html.  Understanding how mod_rewrite works is the most important part of this.  

2) regular expressions.  RewriteRule is the center of mod_rewrite, and the match rules are almost always regular expressions.  Since mod_rewrite uses the same PCRE language you're (probably) familiar with from PHP, this should be no issue for you.  I found the PCRE rules rather simple to learn at a basic level, though they can get extremely complicated.  The 'real' docs are a bit of a dry read, and highly technical to boot, but they are the #1 source for PCRE info: http://www.pcre.org.  If you need a more hand-holding start, try this really good site: http://www.regular-expressions.info/tutorial.html.

With the learning part out of the way, testing just comes on its own.  I've always found the best testing environment is just some throw-away box that was due to be recycled, refurbished just enough to make it run, installed with your favorite flavor of Linux.  I've never set up Apache on Windows, so I don't know if you require anything extra to support PCRE.  Whatever OS you pick, once Apache is up and running, it's all good.  You don't need hundreds and thousands of files in order to test rewrite.  Really, you only need a couple.  Your target page can just be a "you landed here" type of page, since you'll know if the rewrite was successful if you get to where you wanted it to go.  

The most important facet of testing rewrites is the rewrite log.  Setting RewriteLogLevel to 9 will give you just about all the information you need to see if/where your rules are going wrong.  The log entries are extremely detailed and provide quite a lot of insight into how the engine works.  

IME, 99% of the problems with rewrites land at the feet of malformed RegEx, while the last 1% can be attributed to out-of-order rules or similar configuration errors.  Keep in mind that rewrites process until they are all done, or until an [L] modified rule has been matched.  The actions they take are cumulative, too.

And of course, you already know about the best resource for help with "problem" rules...EE  :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
b0lsc0ttIT ManagerAuthor Commented:
Thanks for the great response and info.  Regex is something I have liked and know pretty good.  Right now that is the part I understand the best on this subject but I appreciate and understand your comments on that point.  Thanks for the recommendation for a system to test this and especially letting me know about the log file.  That was very helpful.  Sorry for the delay in a response.  I had hoped for some other comments but am really pleased with what you provided.
b0lsc0ttIT ManagerAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.