The Definitive Guide to Apache mod_rewrite | Search for a title, author or keyword | ||||||||
The Definitive Guide to Apache mod_rewrite By Rich Bowen. mod_rewrite uses a rule-based rewriting engine ( based on a regular-expression parser ) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule to provide a really flexible and powerful URL manipulation mechanism. mod_rewrite, frequently called the “Swiss Army Knife” of URL manipulation and “damned cool voodoo” is the blessing and bane of every Apache user. They know that it can do whatever they want, but they are not always sure how to coax it into doing so. I hope that this book can remove some of the mystery surrounding mod_rewrite and make it more science and less magic for you. Perhaps the most common use of mod_rewrite is to make ugly URLs more attractive. For example, it might be desirable to hide an icky URL like http://www.example.com/cgi-bin/display.cgi?document_name=index and instead have users go to http://www.example.com/doc/index. That can be accomplished very simply with a single RewriteRule, which will allow for an unlimited number of values to appear in place of the “index” in that URL. There are people who believe that URLs that do not contain question marks, ampersands, and other “special characters” will necessarily appear higher in the rankings on search engines. This is, for the most part, completely untrue. However, a large number of firms billing themselves as “search engine optimization” companies have made large sums of money by persuading people otherwise. Many uses of mod_rewrite are conditional. That is, I want the rewrite to happen sometimes, but not always. These can be based on the time of day, the person who is accessing the website, the user’s preferred language, or any other arbitrary criterion. As important as knowing when and how to use mod_rewrite is having a firm grasp on what other tools Apache offers, so that you know when not to use mod_rewrite. All of mod_rewrite’s amazing power comes at the cost of performance. Running regular expressions consumes time and memory, and it’s ideal to avoid it if alternate approaches are available. For example, mod_alias provides the Redirect and RedirectMatch directives, which provide a means to redirect one URL to another. Removing mod_rewrite from a scenario removes complexity and thus makes things run faster. You should consider mod_rewrite as a last solution, rather than as the first tool you reach for in your toolbox. It’s also important to understand that mod_rewrite was written in 1996, when Apache was still rather limited. Ralf Engelschall wrote the module to solve problems that had no other solution. Many of the mod_rewrite tutorials that you may find online come from that era and don’t take into consideration the fact that many of these problems now have easier solutions with standard Apache configuration directives that didn’t exist in 1996. So, even if you encounter an example in a mod_rewrite tutorial or how-to somewhere, this doesn’t necessarily mean that it’s the best way to handle the problem.
|
|||||||||
The Definitive Guide to Apache mod_rewrite | Disclaimer: this link points to content provided by other sites. |