.htaccess mod rewrite

Discussion in 'Apache' started by pixelgod, Apr 9, 2009.

  1. #1
    Hi DP,

    I'm having a little trouble with my mod_rewrite. I want to rewrite the following:

    http://www.domain.com/sites/subdomain -> http://subdomain.domain.com

    http://www.subdomain.domain.com -> http://subdomain.domain.com
    and
    http://www.domain.com/sites/subdomain/images -> http://subdomain.domain.com/images


    I'm very new to .htaccess, and I don't really know what I'm doing. I read the sticky, but it was long and confusing. This is what I've managed to stitch together so far:

    RewriteEngine On
    RewriteRule ^\.htaccess$ - [F]
    RewriteCond %{HTTP_HOST} !^www\.domain\.com?$
    RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com?$
    RewriteRule ^$ sites/%1/ [L]
    RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.domain\.com
    RewriteRule (.*) http://%1.domain.com/$1 [R=301,L]  
    Code (markup):
    I don't know how to make the images folder work, and I've been told that this isn't very efficient, and the server will get stuck in loops under certain circumstances. Thanks in advance!
     
    pixelgod, Apr 9, 2009 IP