Need Help Using Mod_rewrite to rediect Subdomains to Directories

Discussion in 'Apache' started by Garthilk, May 12, 2008.

  1. #1
    Okay,

    What I'm trying to do, is that when a user types a subdomain, if a directory with a coresponding names exists, it will goto that directory.

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www.* [NC]
    RewriteCond %{HTTP_HOST} ^([^\\.]+)\\.mmohell\\.com
    RewriteCond /var/www/vhosts/mmohell.com/httpdocs/games/%1
    RewriteRule ^(.*) /games/%1/$1 [L]
    Code (markup):
    Example. I goto http://red5.mmohell.com it should direct to the /games/red5/ directory if it exists. Instead it keeps going to the root directory.
     
    Garthilk, May 12, 2008 IP
  2. nks

    nks Well-Known Member

    Messages:
    1,602
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Why don't you simply use a 301 Redirect?
     
    nks, May 12, 2008 IP
  3. Garthilk

    Garthilk Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Not sure I understand how a 301 would serve my purpose. Is it possible to do a wildcard subdomain and then have it look for a coresponding directory, and point there if it exists? If it's possible, I'd love to know how.
     
    Garthilk, May 12, 2008 IP