Dynamic Subdomains use domain root

Discussion in 'Apache' started by Silver89, Jul 25, 2010.

  1. #1
    I'm using dynamic subdomains and have the default index setup at the moment but I'm struggling getting it to find other files within the directory?

    http://domain.com/user.php?username=bob

    is now

    http://bob.domain.com

    But how can I change my .htaccess so that

    http://domain.com/newpost.php

    is

    http://bob.domain.com/new

    Here is my current htaccess that doesn't do what I want?

    
    Options -indexes +FollowSymLinks
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.domain\.com
    RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com
    RewriteCond %{REQUEST_URI} !^/user\.php$
    RewriteCond %{QUERY_STRING} !^username=.
    RewriteRule ^(.*) user.php?username=%1 [L]
    
    RewriteRule ^new$ /newpost.php [L]
    
    Code (markup):

     
    Silver89, Jul 25, 2010 IP
  2. nonee

    nonee Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've had a problem doing the same thing a little while ago on one of my projects. I ended up using a wildcard subdomain. A wildcard is good because it will use "whatever.domain.com" and use the same directory as "domain.com", same goes for "whatever.domain.com/script.php" it would be pulling from your public_html directory the script.php and would still be able to parse all of the variables.

    To set up a wildcard dns entry in cpanel just add a new subdomain as *.domain.com (yes, use the asterisk).

    Best of luck,
    Bryan
     
    nonee, Jul 25, 2010 IP