URL Mapping - ApacheCon 2005
mod_rewrite examples (2)
  • Problem: Want arbitrary user to have a website at "username.example.com"

  • Don't want to have to set up vhosts for everyone

  • Solution: "wild-card" cname in DNS:

    
        *   86400   IN  CNAME  www.example.com.
    
      

  • Then, a rewrite rule:

    
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$
        RewriteRule ^(.+)$ /home/%1/public_html$1
    
      

  • %1 contains the match from the RewriteCond

  • $1 contains the match from the RewriteRule

  • Note that you can also do this with mod_vhost_alias

Index
Back to mod_rewrite examples (1)
Forward to mod_userdir and public_html

ApacheCon 2005 : URL Mapping - Slide #39 of 45