Can cPanel treat www.example.com as a separate subdomain?

david364

Active Member
Sep 15, 2013
44
5
58
cPanel Access Level
Reseller Owner
I'm wondering if there is any way to modify an existing account in cPanel/WHM so that www.example.com is treated as a separate subdomain of example.com instead of being aliased? I would like to redirect (Apache Redirect) from one of these virtual hosts to the other without using the rewrite engine.
 
Last edited by a moderator:

david364

Active Member
Sep 15, 2013
44
5
58
cPanel Access Level
Reseller Owner
I found a partial answer: Use cPanel > Redirects. Set "https?://(www.)?" to ** All Public Domains **. Set "www redirection" to "Redirect with or without www.". Click Add.

Now URLs like "example.com" will be redirected to "www.example.com". This is done internally by adding

Apache config:
ServerAlias www.example.com
to the virtual host for domain example.com, so it is faster than using the rewrite engine. Just one thing I don't understand: why does a full redirect occur just because a ServerAlias is used? ServerAlias is not documented as triggering a Redirect.
 

GOT

Get Proactive!
PartnerNOC
Apr 8, 2003
1,772
326
363
Chesapeake, VA
cPanel Access Level
DataCenter Provider
The redirect is in the htaccess. By having the server alias in the config Apache then knows what the home folder and user are among other things and then it knows what htaccess file to read.

I must have misunderstood your question. I thought you wanted www to show different content than non-www without using the rewrite option.
 

david364

Active Member
Sep 15, 2013
44
5
58
cPanel Access Level
Reseller Owner
No, you didn't misunderstand the original question. I piggy-backed. Sorry for the confusion. If I could separate example.com and www.example.com as two different virtual hosts, then a simple Redirect forces all users to use the desired domain name without needing .htaccess or rewrite engine. It works on my non-cPanel development site.