Recipe 5.14 Rewriting Based on the Query String

Problem

You want to translate one URI into another based on the value of the query string.

Solution

Put this in your httpd.conf:

RewriteCond "%{QUERY_STRING}"   "^user=([^=]*)" RewriteRule "/userdirs"         "http://%1.users.example.com/" [R]

Discussion

mod_rewrite does not consider the query string as part of the URI for matching and rewriting purposes, so you need to treat it separately. The given example translates requests of the form:

http://example.com/people?user=jones
http://jones.users.example.com/

The [R] tells mod_rewrite to direct the browser to the URL constructed by the RewriteRule directive.

See Also

  • http://httpd.apache.org/docs/mod/mod_alias.html



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net