Even More On URL Rewriting

I thought it might be helpful if I shared the URL Rewriting rules I built for the Model-Glue version of CFLib. Right now, only two events work, showLibraries and showLibrary. Here are the rules as defined in Apache:

RewriteRule /showLibraries /?event=showLibraries [PT,NC]
RewriteRule /showLibrary/([0-9]+)/(.*) /?event=showLibrary&id=$1 [PT,NC]

This basically means that if ‘showLibraries’ is found in the URL, it should be rewritten to the right event format for MG.

The second rule is a bit more complex. The URLS for linking to a library look like so

/showLibrary/9/StrLib

They include the ID and the library name. So my regex simply checks for “showLibrary”, a value number, and it ignores the string at the end.

I had to rewrite the regex a tiny bit for ISAPIRewrite. It uses different flags for one. (In Apache, NC means ignore case. In ISAPIRewrite, the flag is I.) Also, the ? had to be escaped in ISAPIRewrite.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments