Using Mod Rewrite to Rewrite URLs

The Most Powerful All-in-one SEO Tool Suite

Search Engine Traffic Guide

Get Instant Access

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.

Throughout the Internet, you find examples of Web sites that have been generated dynamically by content management systems. These sites can be information

Using Mod_Rewrite to Rewrite URLs jV

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.

REWRITE A STATIC URL

Open any text editor such as notepad.exe, or open your current .htaccess file.

htaccess - Notepad -

File Edit Format View Help o e

Type RewriteEngine On to activate the mod_rewrite module.

To rewrite a single static URL, add RewriteRule Aold\ .html$new.html [R] .

REWRITE A DYNAMIC URL

4 To rewrite a dynamic URL, add

RewriteRule A([A/]*)\.html$ /viewproducts.php ?category=$1 [L].

This redirects all traffic going to www.example. com/viewproducts.php? category=sports to www.example.com/ sports.html.

UPLOAD TO SERVER

5 Upload the htaccess.txt file to your Web server root directory and rename it .htaccess.

The mod_rewrite module rewrites the URLs to make them appear static.

Was this article helpful?

0 0
SEO Made Easy

SEO Made Easy

Discover How To Get Your Sites On Top of The Search Engines So You Can Generate More Leads and Sales, Introducing... SEO Made Easy'. You'll discover why search engine optimization is important and why you should be optimizing are your pages so people can find your site.

Get My Free Ebook


Post a comment