Apache subdomain redirects to main domain

Solution 1:

OK .. finally figured out the issues.. got it to work

first of all on your host dns ... you need to add the record for your server name I use namecheap.com .. I added a A + Dynamic DNS Record with a host john and my ip address ... same as my A record for www ... I'm assuming its just a standard A Record anywhere else

once that was there .. it may take a while before you can actually ping it once you can .. you will be good to go if all your other settings were correct

Ok now for the configuration files i used.. I created two in sites-available..

the first one was called 001-john.conf I found out that it is important to have the file end in .conf or you wont be able to use a command that seemed to fix the issue.

In that configuration I added the following :

<VirtualHost *:80>
    ServerAdmin [email protected] (of course you would use your domain name instead of mysite.com)
    ServerName john.mysite.com
    ServerAlias john.mysite.com
    DocumentRoot /web/john (of course you would make the root the path to the folder where the files are stored)

<Directory />
    Options FollowSymLinks ExecCGI
    AllowOverride ALL
</Directory>
<Directory /web/john/>
            Options ExecCGI FollowSymLinks Includes Indexes (or whatever directives you want)
            AllowOverride ALL
            order allow,deny
            allow from all
</Directory>

ScriptAlias /cgi-bin/ /web/plus/cgi-bin/  (if you wanted to create a cgi bin use your correct path for this)
<Directory "/web/plus/cgi-bin">
    AllowOverride ALL
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>
ErrorLog /var/log/apache2/errorjohn.log
CustomLog /var/log/apache2/accessjohn.log combined
</VirtualHost>

the second configuration file was for ssl and i called it 001-john-ssl.conf It looked like this:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName john.mysite.com
        ServerAlias john.mysite.com
        DocumentRoot /web/john

<Directory />
    Options FollowSymLinks
    AllowOverride ALL
</Directory>

<Directory /web/john/>
    Options Indexes FollowSymLinks Includes MultiViews ExecCGI
    AllowOverride ALL
            Require all granted
</Directory>


ScriptAlias /cgi-bin/ /web/plus/cgi-bin/
<Directory "/web/plus/cgi-bin">
    AllowOverride ALL
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>




    LogLevel warn
    ErrorLog /var/log/apache2/errorjohn.log
    CustomLog /var/log/apache2/accessjohn.log combined

   SSLEngine on
   SSLProtocol all -SSLv2
   SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
   SSLCertificateFile    /etc/apache2/ssl/your.crt file
   SSLCertificateKeyFile /etc/apache2/ssl/your.key file
   SSLCACertificateFile /etc/apache2/ssl/your.ca-bundle
   SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
</VirtualHost>
</IfModule>

once that was all saved I ran

sudo a2ensite 001-john.conf

and

sudo a2ensite 001-john-ssl.conf

Then I ran

sudo service apache2 reload

Then to check to see if it had both .. which before it didnt before .. I just created links from site-available to site-enabled .. that didnt seem to work for me but after running a2ensite with the files labeled with the .conf extention..I ran apachectl -t -D DUMP_VHOSTS and had this result:

VirtualHost configuration:
*:443                  is a NameVirtualHost
         default server mysite.com (/etc/apache2/sites-enabled/000-default-ssl.conf:2)
         port 443 namevhost mysite.com (/etc/apache2/sites-enabled/000-default-ssl.conf:2)
         port 443 namevhost john.mysite.com (/etc/apache2/sites-enabled/001-john-ssl.conf:2)
                 alias john.mysite.com
*:80                   is a NameVirtualHost
         default server mysite.com (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost mysite.com (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost john.mysite.com (/etc/apache2/sites-enabled/001-john.conf:1)
             alias john.mysite.com

**just as a note .. my original site is located in directory /web/public and the subdomain site is located at /web/john... since yours was located at /var/www/html I would probably use something like /var/www/forum for you subdomain folder to store your forum files in and i would use forum.yoursite.com as the ServerName and ServerAlias but hopefully with the example you will see the format and setup of everything.

once the dns records got updated from namecheap .. i was able to access john.mysite.com and it would show the simple "under construction" file in there and if i just went to www.mysite.com it would give me my normal page that was setup a while ago

so now its working with a subdomain

Hopefully this will help you through and set things up properly .. most likely its because the configuration files probably didnt have the .conf extensions and you didnt use a2ensite to enable them.. that seemed to be the problem i was running into