This article is an introduction to URL rewrites using Apache's mod_rewrite module.
Apache's mod_rewrite module enables you to rewrite URLs. You can use URL rewrites in a number of scenarios, including:
To specify URL rewrite rules, you use directives such as RewriteRule and RewriteCond in an .htaccess file. These directives rely heavily on regular expressions to provide URL pattern matching. There are many mod_rewrite options available, and describing all of them is beyond the scope of this article. However, here is an example of a URL rewrite using the mod_rewrite module:
RewriteEngine on RewriteRule ^products/calculator$ /products.php?id=232&cat=11
In this example, visitors who use the URL products/calculators will actually view products.php?id=232&cat=11, though they will be unaware of this (the location bar in their browser still displays /products/calculators). The RewriteEngine directive simply enables or disables URL rewriting, while the RewriteRule directive does the actual work of matching an incoming URL and specifying the target URL.
For more examples of the mod_rewrite module in action, please see these articles:
For more information about how to use the mod_rewrite module, please visit http://httpd.apache.org/docs/current/mod/mod_rewrite.html.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.