Forum Moderators: phranque
I use Cpanel and WHM on one of my servers. I go to the cpanel of my domain MYSITE.COM and create a subdomain XYZ.MYSITE.COM, which works, I can see XYZ.MYSITE.COM.
However, I have two problems:
1. MYSITE.COM also has two addon domains MYSITE2.COM and MYSITE3.COM. So to associate the subdomain with these add on domains, I have this in my httpd.conf:
<VirtualHost 99.99.99.99>ServerName XYZ.MYSITE.COM
ServerAlias www.XYZ.MYSITE.COM XYZ.MYSITE2.COM XYZ.MYSITE3.COM
DocumentRoot /home/MYSITE/public_html/XYZ
User mysite
Group mysite
</VirtualHost>
Such virtualhost definition works for XYZ.MYSITE.COM but does not show up for XYZ.MYSITE2.COM and XYZ.MYSITE3.COM. What am I doing wrong? I have specified it in the "ServerAlias" section -- are subdomains also mapped to addon domains? (MYSITE2.COM and MYSITE3.COM work in general as mirror domains of MYSITE.COM).
2. Second, for XYZ.MYSITE.COM I don't want it to necessarily point to a folder inside my "public_html" folder. I instead want to capture this subdomain pattern in my .htaccess for the overarching domain name (MYSITE.COM) and then do an internal rewrite to a PHP program. That is:
I do not want this:
xyz.mysite.com --> /home/mysite/public_html/xyz/
I want this:
xyz.mysite.com --> /home/mysite/public_html/1.php?a=xyz
So I have this in my httpd.conf file for the MYSITE.COM domain:
RewriteCond %{HTTP_HOST} ^XYZ\.MYSITE\.COM
RewriteRule ^(.*)$ [MYSITE.COM...] [L,R=301]
But this is not working. What am I doing wrong?
Thanks for any help!
What works:MYSITE.COM
MYSITE2.COM (addon domain to MYSITE.COM)
XYZ.MYSITE.COM (subdomain on MYSITE.COM)What doesn't work:
XYZ.MYSITE2.COM
I have added XYZ.MYSITE2.COM to the ServerAlias directive of the subdomain VirtualHost, but it still doesn't work. This was over 48 hours ago, so it's not a matter of DNS propagation and such. Would appreciate knowing how this can be done for addon domains, thanks!
What doesn't work:XYZ.MYSITE2.COM
I'm wondering if this is a problem with the A record for the DNS wild-card -- could be something as simple as leaving the required period off the end of the domain name.
You might also want to dig into the httpd.conf code changes generated by cPanel. Because it uses templates to generate code for the most common 'features' that it offers, it often generates each of those features in a flexible manner, but the generated features themselves are not flexible; In other words, it might be able to add "add-on" domains, but not subdomains. This is just a guess, but having been bitten by cPanel (and other control panels) many times in the past, I studiously avoid using it -- and avoid hosting where no other config options are offered.
Jim
The DNS stuff has periods at the end of both MYSITE.COM and MYSITE2.COM. But I went into the named file for both domains and indeed I had to add the A record there for the addon domains as well, and it works! (Feel stupid) -- thanks!
Now, how should I make sure that the subdomain points to an internal redirect? For instance:
Currently:
[XYZ.MYSITE.COM...] --> [MYSITE.COM...]
What I want:
[XYZ.MYSITE.COM...] --> [MYSITE.COM...]
I am not sure where the code for this should sit. In the "VirtualHost" entry for MYSITE.COM or for XYZ.MYSITE.COM? I am trying this code inside XYZ.MYSITE.COM virtualhost directive:
RewriteRule ^([^/\.]+)/?$ http://MYSITE.COM/XYZ/$1 [L,R=301]
Which works, because of a RewriteRule in the VirtualHost directive of MYSITE.COM that maps the XYZ to "index.php?type=XYZ".
But I would like an "internal redirect" instead of this above kind of inefficient external redirect from the subdomain to the main domain. So I suppose I need to do this in the VirtualHost Directive of the main MYSITE.COM domain, but I am not sure how. Any pointers?
So many thanks!
An external 301 redirect is visible in the browser address bar, and tells search engines to discard the originally-requested URL and use the new one instead.
An internal rewrite simply tells the server what filepath to use to serve content for the requested URL.
So using those two facts, you should be able to figure out what needs an external redirect and what needs an internal rewrite.
Where possible, try to avoid extra steps. But be wary of exposing your (sub)domain-to-subdirectory mapping to the client; There is no need to do so, and doing so invites both erroneous linking and malicious linking problems, both causing duplicate-content issues (where a page is accessible with two or more URLs).
Jim