How do I redirect visitors from https://domain.net to https://www.domain.net ? Using an A record or some other DNS settings?
I am asking because I made the mistake of purchasing an SSL certificate for www.domain.net...
Thanks for any ideas!
How do I redirect visitors from https://domain.net to https://www.domain.net ? Using an A record or some other DNS settings?
I am asking because I made the mistake of purchasing an SSL certificate for www.domain.net...
Thanks for any ideas!
You'll need to set up your webserver to send a redirect to the browser. Here's how I do this in Apache.
Point both the DNS records to the same IP address (for example with a CNAME alias), and place the below code in a virtualhost that listens on this address. You'll also need to have mod_rewrite enabled.
# Do an external redirect:
# Places www in front of the domain, but only if there's no www or other subdomain yet.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^.*\..*\..*$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [R=301,L]
https://
... in the RewriteRule. You might also want to add RewriteCond %{HTTPS} =on
to avoid redirecting plain http traffic to https (unless that's what you want).
Jul 6, 2010 at 0:02
As andrushka and Martijn Heemels said, you need to configure a web server to redirect clients to the www. address. But since this is https we're talking about, it's more complicated than that. When the browser client opens an SSL connection to to the server it thinks of as www.domain.net, it expects the server to respond with a certificate that's valid for that domain before it sends the HTTP request (and thus gets a redirect in response). If your server just has a cert for domain.net, you'll get a certificate warning. There are several ways to deal with this:
1- Live with it, and configure the server to redirect clients to the correct domain (after they get the cert warning). Not great for security, as you're training your users to trust any random impostor site that pretends to be you...
2- Don't bother with the redirect, just serve the same content under both www.domain.net and domain.net. Your users are going to get the same warning either way, so there's not much point in redirecting (unless you want it for some other reason, like URL consistency).
3- Get a dual-domain cert that's valid for both www.domain.com and domain.com (one as the cert's Subject, the other in a Subject Alternative Name extension), and use it with either of the first two approaches. I haven't tried them, but I think StartSSL's free certs include this capability.
4- Get a separate cert for domain.net, and run a second server (or a virtual server on a different IP address) to handle the redirects. It has to be on a different IP address so it knows which certificate to use before it sees the client's HTTP request.
5- Get a separate cert for domain.net, run a second virtual server on the same IP address using server software new enough to support the Server Name Indication extension to SSL/TLS (i.e. Apache 2.2.12 or later), and hope that the client's browser is also new enough (some will be, some won't).
DNS servers can not perform HTTP redirect. You should use a webserver to do the 301 redirection. All modern servers like Apache / lighttpd supports HTTP redirection. You can also use third party tools like http://redirect.200please.com
Remember, never use CNAME to redirect
I believe there are ways to redirect domains using a free webservice or developing your own tool.
Try this:
Why not just talked to the SSL seller and ask to rename the SSL certificate you have purchased?
If you aren't comfortable with messing with your web server's configuration files, many scripting languages can also issue the HTTP redirect. Here's a PHP example:
if ($_SERVER['HTTPS']!="on")
{
header('Location: https://yoursite.com/'.$_SERVER["REQUEST_URI"]);
exit;
}