0

Possible Duplicate:
apache redirect from non www to www

Is it possible to configure DNS to add www. prefix to the domain name?

Here is an example of this

Community
  • 1
  • 1
Richard
  • 14,427
  • 9
  • 57
  • 85

3 Answers3

1
  1. You should add a NS A entry to the DNS record for both normalurl.com and www.normalurl.com
  2. Enable mod_rewrite on Apache and create a .htaccess file with the following entries:
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.normalurl.com$ [NC]
RewriteRule ^(.*)$      http://www.normalurl.com/$1 [L,R]
bbb
  • 702
  • 3
  • 6
  • `.htaccess` is bad. Better to add some mod_alias stuff to the vhost configuration file, in order to be sure redirection always happens / avoid infinite redirect-loops, etc. Plus, that's way much easier to read configuration, if it's all in one place.. – redShadow Dec 24 '11 at 13:10
  • This is correct if you do have access to the vhost configuration; it might be an issue on many shared hosting environments, though. – bbb Dec 24 '11 at 13:31
1

Nope. You have to configure the webserver at yourdomain.com to redirect to www.yourdomain.com.

For example, on apache, you can use this configuration (using mod_alias):

<VirtualHost *:80>
  ServerName www.yourdomain.com
  ## Actual configuration here...
</VirtualHost>

<VirtualHost *:80>
  ## redirect non-www to www
  ServerName www.yourdomain.com
  ServerAlias yourdomain.com

  RedirectMatch permanent ^(.*) http://www.yourdomain.com$1
</VirtualHost>
redShadow
  • 6,687
  • 2
  • 31
  • 34
0

A DNS response contains a mapping of a domain name to an IP address. While you could alias example.net to www.example.net with a CNAME record, this would not be visible for the user.

Most likely, you want to configure your web server to send an HTTP 301 redirect to the correct URL.

Community
  • 1
  • 1
phihag
  • 278,196
  • 72
  • 453
  • 469