MOD_REWRITE + subdomains

Discussion in 'Apache' started by S2X, Jun 4, 2006.

  1. #1
    How would I do something like this:


    Original URL: mysite.com/page.php?q=games&i=pacman


    I need to mod_rewrite that to: games.mysite.com/pacman.aspx
     
    S2X, Jun 4, 2006 IP
  2. sarathy

    sarathy Peon

    Messages:
    1,613
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put this in your root .htaccess

    Options +FollowSymlinks

    RewriteEngine on
    RewriteBase /


    RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.mysite\.com$ [NC]
    RewriteRule ^[^/]+\.aspx$ /page.php?q=%2&i=$1 [QSA,L]

    you have to setup your subdomain first for this to work or you can have wildcarded dns setup.
     
    sarathy, Jun 8, 2006 IP