0

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?

2 Answers 2

2

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.

8
  • This does not work in my case since foo.example.com points to another server.
    – To Do
    Commented Mar 12, 2013 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
    Commented Mar 12, 2013 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
    Commented Mar 12, 2013 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
    Commented Mar 12, 2013 at 22:35
  • No I need to redirect the subdomain from Apache to IIS and www.subdomain to subdomain.
    – To Do
    Commented Mar 12, 2013 at 22:49
0

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.

5
  • The cname record is pointing in the opposite direction: www.foo.example.com -> foo.example.com
    – To Do
    Commented Mar 12, 2013 at 21:38
  • The A record is already set. Deleting the CNAME record makes the www.foo.example.com give a 404 error.
    – To Do
    Commented Mar 12, 2013 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
    Commented Mar 12, 2013 at 21:53
  • You can use .htaccess.
    – Nilabh
    Commented Mar 12, 2013 at 21:57
  • RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
    – Nilabh
    Commented Mar 12, 2013 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.