Basic Understanding of Mod-Rewrite
A Beginners Guide to URL Redirection
A Guide for Understanding and Beginning Mod-Rewrite URL Redirects
The Goal: To provide basic understanding of Apache's® Mod-Rewrite to those who would like to use, understand or know the basics of how URL Redirection with Mod-Rewrite works.
After deciding to use a php driven mysql database, I realized I would need friendly URL's for search engines. I checked in a number of forums, then I searched search engines, then I searched forums, then I searched sites, (did I mention searching?)... everything I found said things like,
"First we notice that from version 3.0.0 mod-rewrite can also use the "ftp:" scheme on redirects. And second, the location approximation can be done by a rewritemap over the top-level domain of the client. With a tricky chained ruleset we can use this top-level domain as a key to our multiplexing map..." *
When I read this, my first thought was, "OK, now in english and maybe a little slower..."
So, learning first hand there was a need for basic, plain english defining of mod-rewrite, I decided to write a guide for those who would like to understand mod-rewrite without all the ultra-technical, "If you weren't a logic major, you can't use it," documentation that surrounds the subject.
That said, let me get started with what you need to know, plan for and implement to make URL redirection with mod-rewrite work for you. Keep in mind this guide is basic and lays the foundation to begin writing rules. It is designed to teach how to understand mod-rewrite URL redirection and to be able to read rules effectively, so if you already know the what and the how... it's probably not for you.
URL Redirection and Mod-Rewrite the Beginning
To begin understanding URL redirection with mod-rewrite, you first have to know what it is not. It is not magic. It is not a way to make a URL appear out of thin air. It is not a way to create content that does not exist.
So what is it? Mod-Rewrite is, very simply, a way to direct your server to respond in a specific way to a request it receives. Period. That's it.
"What's so special about mod-rewrite then?" Glad you asked.
The special, (and for some certain control freaks, yes, including myself, exciting), part of URL redirection with mod-rewrite is it puts you in control of your website. Including, who visits your site, what pages they are allowed to see, what URL's a search engine or visitor sees, and much, much more...
So, in short URL redirection with mod-rewrite is not magic, but rather control. The more you understand it, the more control you will ultimately have.
(For simplicity, and since this is a beginning guide, I will only cover the htaccess type of ruleset, since that is the most easily accessible and less inclined to create an infinite server loop, which could require a re-boot to be broken.)
Links to other, more advanced, resources are provided on the 'finally starting' page.