mod_rewrite/preg_match - yes/no, is there better way?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ja NE

    mod_rewrite/preg_match - yes/no, is there better way?

    I would like to offer my registered users to have very short uri for
    their pages in our comunity site, so I have enabled wildcard dns
    *.bellay.com. and added virtaul host for it. (I'm testing this on one
    domain I don't use so no harm will be done in testing time). and that is
    working. than I tried to write mod_rewite rule in .htaccess which should
    redirect anything.bellay .com to bellay.com/index.php?user= anything but I
    failed.

    rewriteEngine On
    rewriteCond %{HTTP_HOST} !^$
    rewriteCond %{HTTP_HOST} !^(www\.)?bella y\.com$ [NC]
    rewriteCond %{HTTP_HOST}<->%{REQUEST_UR I} ^(www\.)?([^.]+).*<->/([^/]+)
    [NC]
    rewriteCond %2<->%3 !^(.*)<->\1$ [NC]
    rewriteRule ^(.+) /%2/index\.php\?use r\=$1 [L]


    so, I delitet those lines from .htaccess file and in my index.php, I put
    on very top:

    $server_host = explode('.', $_SERVER['HTTP_HOST']);
    $subdomain = strtolower($ser ver_host[0]);
    $not_users = "/\b(www|ftp|dev| mail|smtp|pop|s erver|localhost |root)\b/i";
    if (preg_match($no t_users,$subdom ain)) {
    echo" header(\"Locati on: http://bellay.com/\");";
    }
    else {
    echo" header(\"Locati on:
    http://bellay.com/?user=$subdomai n\");";
    }

    and that is working, but, before I implement that on my real site, I
    have to ask if there is any bettar way to do that? are there any
    drowbacks or potential (security) dangerous waitnig for me?

    thank you very much.
Working...