mod_rewrite is one of the most famous URL manipulating module available in Apache web server.
One of the most common drawbacks of a language like PHP is its inability to generate SEO friendly URLs.
mod_rewrite is very useful for SEO and certainly required for any dynamic website in order to achieve Google Top 10 ranking.
Lets take an example.
The existing URL for a product on SwamiPC
http://www.swamipc.co.uk/desktop-pc/acer/acer-veriton-m460-c2d-e4400-1gb-160gb-dvdrw-xpp
could have been something
http://www.SwamiPC.co.uk/node/2
without mod_rewrite.
mod_rewrite modules gives flexibility to rewrite the URLs on fly.
It provides unlimited number of rewrite rules and not only that it also provide flexibility to implement mod_rewrite on directory/subdirectory (.htaccess) level or domain level (httpd.conf).
The most common method to implement mod_rewrite rule is in .htaccess as httpd.conf will normally not available to end users.
.htaccess also offers you to rewrite URLs in directory level.
mod_rewrite directives
Following are the most common mod_rewrite directives
RewriteEngine
Syntax: RewriteEngine on|off
This directive is used to switch mod_rewrite engine on or off
RewriteOptions
Syntax: RewriteOptions option
This directive is used to set some special options.
E.g.
RewriteOptions MaxRedirects 19
RewriteLog
Syntax: RewriteLog filepath
This directive is used to specify the log file for capturing mod_rewrite logs which comes handyduring debugging.
E.g.
RewriteLog “/var/home/user/ajay/logs/rewritelog.log”
RewriteRule
Syntax: RewriteRule pattern substitution
This is the most important directive which we look for. This directive is used to define rewrite rule.
It is defined per rule and can be used as many times as required.
pattern is a POSIX regular expression
Links
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html
Tags: Google Top 10, mod_rewrtie, SEO
















































Leave a Reply