<-
Apache > HTTP Server > Documentation > Version 2.3 > Rewrite

When not to use mod_rewrite

Available Languages:  en 

This document supplements the mod_rewrite reference documentation. It provides a few advanced techniques and tricks using mod_rewrite.

Note that many of these examples won't work unchanged in your particular server configuration, so it's important that you understand them, rather than merely cutting and pasting the examples into your configuration.

See also

top

URL-based sharding accross multiple backends

Description:

A common technique for distributing the burden of server load or storage space is called "sharding". When using this method, a front-end server will use the url to consistently "shard" users or objects to separate backend servers.

Solution:

A mapping is maintained, from users to target servers, in external map files. They look like:

user1  physical_host_of_user1
user2  physical_host_of_user2
:      :

We put this into a map.users-to-hosts file. The aim is to map;

/u/user1/anypath

to

http://physical_host_of_user1/u/user/anypath

thus every URL path need not be valid on every backend physical host. The following ruleset does this for us with the help of the map files assuming that server0 is a default server which will be used if a user has no entry in the map):

RewriteEngine on

RewriteMap      users-to-hosts   txt:/path/to/map.users-to-hosts

RewriteRule   ^/u/([^/]+)/?(.*)   http://${users-to-hosts:$1|server0}/u/$1/$2

Available Languages:  en