Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

i am using wildcard with apache

my APACHE CONFIG:

ServerAlias *.staronece1.com
DocumentRoot /staronece1/domains

my named file

$ttl 38400
staronece1.com.      IN      SOA     staronece1.com. email.yahoo.com. (
                        1334838782
                        10800
                        3600
                        604800
                        38400 )
staronece1.com.      IN      NS      staronece1.com.
staronece1.com.      IN      A       95.19.203.21
www.staronece1.com.  IN      A       95.19.203.21
server.staronece1.com. IN     A      95.19.203.21
mail.staronece1.com. IN      A       95.19.203.21
ns1.staronece1.com.  IN      A       95.19.203.21
ns2.staronece1.com.  IN      A       95.19.203.21
staronece1.com.      IN      NS      ns1.staronece1.com.
staronece1.com.      IN      NS      ns2.staronece1.com.
staronece1.com.      IN      MX      10 mail.staronece1.com.
* 14400 IN A 95.19.203.21
*.staronece1.com IN A 95.19.203.21

my php test file

/staronece1/domains/index.php



<?php

    function getBname(){
        $bname=explode(".",$_SERVER['HTTP_HOST'],2);
        return $bname[0];
    }

    echo 'SubDomain is :'.getBname();
?>

if i go to something.staronece1.com

i get this result SubDomain is : something

No the problem is

if i go to www.staronece1.com

i should get empty result, because www is not a sub domain

but i get this result

SubDomain is : www

And if i go to www.something.staronece1.com

i get firefox error message ( site not found )

How to fix this problem??

i think the solution is: added record for www in named file

Thanks

share|improve this question
4  
www is most definitely a subdomain. –  Skyhawk Jul 7 '12 at 23:20
    
@Miles, How to fix this problem? –  Alaa Gamal Jul 7 '12 at 23:27

2 Answers 2

As Miles commented, www is a regular subdomain that is no different to something. It's very misleading in that sense, and it's not your fault that you have them confused.

For one, the DNS zones are irrelevant: www.staronece1.com must resolve to something, or the website won't work at all, so leave that alone.

If you really want this behaviour, you need a separate ServerAlias www.staronece1.com before your current wildcarded ServerAlias.

Name-based virtual hosts for the best-matching set of s are processed in the order they appear in the configuration. The first matching ServerName or ServerAlias is used, with no different precedence for wildcards (nor for ServerName vs. ServerAlias).

http://httpd.apache.org/docs/current/mod/core.html#serveralias

share|improve this answer

Im not sure i understand what the problem is. The server is acting as it is supposed to. If the problem is that www.something.staronece1.com is not working, then add a dns record for www.something.staronece1.com and add another serveralias line to your httpd.conf:

ServerAlias *.*.staronece1.com

ideally, add it below the other ServerAlias lines.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.