How do I make subdomains point to a subfolder with .htaccess?

Discussion in 'Apache' started by desbest, Jan 26, 2009.

  1. #1
    How do i convert

    http://something.domain.com to --> xxhttp://domain.com/something
    using .htaccess
    tricking the browser and person into thinking they have an actual subdomain


    I got this code though.
    
    RewriteEngine On
    Options Indexes FollowSymlinks Multiviews
    RewriteBase /
    RewriteCond %{HTTP_HOST} forum.hostingz.org
    RewriteCond %{REQUEST_URI} !forum/
    RewriteRule ^(.*)$ xxhttp://www.hostingz.org/forum/$1 [L]
    
    Code (markup):


    What it does is that it redirects xxhttp://forum.hostingz.org to xxhttp://hostingz.org (ps im not posting links so dont ban or warn me)
    But by redirecting the url changes, is there a way I can use masking or something like that so url doesn't redirect?
     
    desbest, Jan 26, 2009 IP
  2. desbest

    desbest Active Member

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #2
    
    RewriteEngine on
    
    
    # Rewrite <subdomain>.example.com/<path> to example.com/<subdomain>/<path>
    #
    # Skip rewrite if no hostname or if subdomain is www
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    # Extract (required) subdomain (%1), and first path element (%3), discard port number if present (%2)
    RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.hostingz\.org(:80)?<>/([^/]*) [NC]
    # Rewrite only when subdomain not equal to first path element (prevents mod_rewrite recursion)
    RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
    # Rewrite to /subdomain/path
    RewriteRule ^(.*) /%1/$1 [L]
    
    Code (markup):
     
    desbest, Mar 1, 2009 IP