Mod_Rewrite can Rewrite your URLs
No Comments
Written by Anders on August 17, 2008 – 8:58 pm
Throughout this blog post there are many references to the importance of proper URL structure for search-engine optimization. The mod_rewrite module of the Apache Web server gives you the power to rewrite poorly formed URLs on the fly as well as manipulate the appearance of any file name you choose. Using the mod_rewrite module may appear difficult at first, but there are tools available to simplify the complex parts, and the benefits of using this module to its fullest extent far outweigh the steep learning curve.
Mod_rewrite is an Apache Web server module that enables you to redirect users from one URL to another URL without the user experiencing any indication that the redirect took place. Mod_rewrite can be used in conjunction with what you have learned about proper URL structuring to generate both search-engine-friendly and user-friendly URLs with ease.
This is especially relevant for Web sites that employ any type of content management system that generates URLs dynamically. These dynamically generated URLs are rarely constructed with search-engine optimization in mind, and due to limitations in the content management software, it can be impossible to fix without the use of mod_rewrite.
Using Mod_Rewrite to Rewrite URLs
Throughout the Internet, you find examples of Web sites that have been generated dynamically by content management systems. These sites can be information portals or large e-commerce Web shops, and the URLs often resemble something similar to www.example.com/ viewproduct.php?cat=pets&subcat=dogs&type=food.
Numerous reasons have already been discussed regarding why this URL structure is inefficient for both the search engines and your visitors. Use mod_rewrite to easily and noninvasively restructure the URL to look like www.example.com/pets/dogs/food. The new URL is more logical, well structured, and in the eyes of search engines and users alike, more relevant and authoritative.
Activate mod_rewrite by adding the text RewriteEngine On to your Web root directory’s .htaccess file. If the file does not already exist, create a blank file and upload it to your Web root directory. The mod_rewrite module is not present on all servers, so be sure to contact your Web hosting administrator to make sure that it is installed. If it is not installed or if your host does not use the Apache Web server, ask if an alternative solution is available.
Activate mod_rewrite by adding the text RewriteEngine On to your Web root directory’s .htaccess file.
Mod_rewrite can be very complex and difficult to use if you are not a skilled Web programmer. Luckily, it is so commonly used that many tools have been developed to help. An excellent, free tool can be found at www.mod-rewrite-wizard.com to assist in rewriting dynamic URLs into well-structured URLs that appear static.
The tool itself can seem complex at first, but with a little practice, it is an invaluable resource. First, enter an example of the type of dynamic URL, and then choose which variables you want to remain static. You also have the option to add any relevant keywords as a prefix or suffix. Generate individual rewrites for specific pages, or take it a step further and generate general rules that rewrite an entire set of pages.
For example, if your Web site contains a dynamically generated shopping mall with product pages of the form www.example.com/products.php?category=health&subcat=eyes&prodid=1, the URL can be rewritten to www. example.com/health/eyes/1.html; you can also automatically rewrite www.example.com/products.php? category=sports&subcat=baseball&prodid=3 to www.example.com/sports/baseball/3.html. As long as your link structure is consistent throughout your entire Web site, only one mod_rewrite rule is necessary.









