I have performed a web search for the question but totally disappointed with the results. The case is to redirect all requests to domain.com to subdomain www.domain.com.
So what I have:
I understand this is possible using .htaccess and PHP. But I want to figure out how this can be done using DNS only. I also understand that the result of the DNS query doesn't change what happens in the HTTP layer so the originally entered domain name will always be the one that's sent to the web server in the Host. So to rewrite domain.com to www.domain.com I will still need Apache mod_rewrite. But I want to do main part of work with DNS (CNAME and A records).
So the main question is what CNAME and A records each domain above should have?
If you have set up URL forwarding on your domain name, but the forward isn't working, there are a few things that may be causing the issue. First, make sure that your domain name is using Name.com's default nameservers. If you are using someone else's nameservers, then the forwarding record will not work.
To Disable an Addon Domain RedirectIn the “DOMAINS” section, click the “Addon Domains” link or icon. Click the “Manage Redirection” link corresponding to the Addon domain you wish to manage. In the “Disable Addon Domain Redirection” section, click the “Disable Redirection” button.
Redirecting Your Domain to www URL. Keep the Type as the default, Permanent(301). Select your domain name from the drop down menu on the next line. In the redirects to text box, type in the full URL of your domain, including www (e.g. http://www.yourdomain.com). Select the radio button next to Do Not Redirect www.
You could make www.domain.com the A record and all the other domainnames CNAMEs of www.domain.com. But this only "solves" that if the IP address of www.domain.com changes you don't have to alter the other DNS enties as they are aliases.
So on the DNS level there is no way to enforce a redirect. And for a good reason because DNS is used for more then only HTTP. For example if all request for domain.com would redirect to www.domain.com your email addresses will change to [email protected].
So for HTTP redirection you will have to use an HTTP solution. This can be at the webserver level (mod_rewrite, in code, javascript (ugh), etc..) but you could also have a proxy in front of your webserver to handle this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With