My issue is simple but I can't seem to find the solution.
I have a domain www.domain.com that has subdomains.
www.domain.com 's document root is /home/domain/public_html
Subdomains (excluding www) need to be redirected to example.com
i.e. abc.domain com need to be redirected to /home/example/public_html
Also, the url needs to be retained. i.e. abc.domain.com
need to show in the address bar.
What I have done till now I have maintained in httpd.conf the following entry under
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)domain.com$
RewriteRule ^.*$ http://%1example.com$0
However, the url is changing to abc.example.com and www.domain.com is being redirected to www.example.com too.
Please suggest the best way to resolve this.
Virtual Hosts configuration, without Rewrite rules,
<VirtualHost *:80>
ServerName domain.com
ServerAlias *.domain.com www.domain.com
DocumentRoot /home/domain/public_html
UseCanonicalName Off
## User abc # Needed for Cpanel::ApacheConf
UserDir enabled abc
<IfModule !mod_disable_suexec.c>
<IfModule !mod_ruid2.c>
SuexecUserGroup abc abc
</IfModule>
</IfModule>
<IfModule mod_ruid2.c>
RMode config
RUidGid abc abc
</IfModule>
<IfModule itk.c>
AssignUserID abc abc
</IfModule>
</VirtualHost>