Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have a Cpanel web hosting account and have created a subdomain which redirects to an IP address of a different server (Windows IIS) by creating an A record. I don't have control of the Windows server.

I would like that those people who type www. before the subdomain get redirected to the same page.

I tried creating a CNAME record pointing www.foo.example.com. to foo.example.com but it isn't working. It is actually stopping the A record from working.

How do I redirect www.foo.example.com. to foo.example.com in Cpanel?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Your cPanel may have an interface to do that for you. What needs to be done, which is what such interface would do anyway, is modifying the .htaccess file in your public_html directory. It will add the following lines:

RewriteEngine ON

RewriteCond %{HTTP_HOST} ^www.foo.example.com$
RewriteRule ^/?(.*)$ http://foo.example.com/$1 [R=301,L]

Omit the RewriteEngine ON line if it is already there.

share|improve this answer
    
This does not work in my case since foo.example.com points to another server. –  To Do Mar 12 '13 at 10:12
    
@ToDo - Have you tried? I have cross-server redirects like this which work for top-level domains, so I do not see why it wouldn't work for a sub-domain. Are you sure your DNS are set correctly? –  Itai Mar 12 '13 at 13:39
    
Yes I did try. I cannot put the .htaccess on the host where the site is. It is a Windows IIS server that I don't have control of. –  To Do Mar 12 '13 at 21:37
    
@ToDo - Oh. I am confused. You need to redirect from IIS to Apache? The question made me think it was the other way around since I've only seen cPanel on Apache servers which is the one that uses .htaccess files. –  Itai Mar 12 '13 at 22:35
    
No I need to redirect the subdomain from Apache to IIS and www.subdomain to subdomain. –  To Do Mar 12 '13 at 22:49
show 3 more comments

You can follow these 2 steps in order to achieve the same.

Step 1) Delete the CNAME record that is redirecting(at the DNS Level) www.foo.example.com to foo.example.com.

In order to do this, You will have to log-in to the Advanced DNS Zone editor present in your cPanel and delete the following CNAME record: www.foo.example.com IN CNAME foo.example.com.

Step 2) You will have to add an A record pointing foo.example.com pointing to the concerned IP address.(IPv4 or IPv6).

The A record will be similar to this: foo.example.com IN A x.x.x.x

where x.x.x.x is the IP address assigned by your web hosting provider.

share|improve this answer
    
The cname record is pointing in the opposite direction: www.foo.example.com -> foo.example.com –  To Do Mar 12 '13 at 21:38
    
Thanks TO Do..Edited the same. (y) –  Nilabh Mar 12 '13 at 21:42
    
The A record is already set. Deleting the CNAME record makes the www.foo.example.com give a 404 error. –  To Do Mar 12 '13 at 21:47
    
Creating two A records is not my question. I want that when a user enters www.foo.example.com he gets redirected to foo.example.com. –  To Do Mar 12 '13 at 21:53
    
You can use .htaccess. –  Nilabh Mar 12 '13 at 21:57
show 1 more comment

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.