Suppose I've Web addresses with query string parameters such as these:


Using mod_rewrite, how do i redirect these to SES Web addresses such as these?

RewriteCond %{QUERY_STRING} book=(\w+)&page=(\d+)  
RewriteRule ^index.php /%1/%2? [R=301]

Because RewriteRule only compares the path (as much as although not such as the question mark), use RewriteCond to capture the values within the query string.

Observe that the matches from RewriteCond are taken in %1, %2, etc., instead of $1, $2, etc.

Also note the ? in the finish of RewriteRule. It informs mod_rewrite to not append the initial query string towards the new URL, which means you finish track of /DesignPatterns/151 intead of /DesignPatterns/151?book=DesignPatterns&page=151.

The [R=301] causes the server to transmit back a redirect response. Rather than spinning, it informs the customer to test again using the new URL. The =301 causes it to be a lasting redirect, to ensure that, among other things, search engines like google knows to exchange that old URL using the new URL in their indexes.