Dns添加www前缀? [重复]

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

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>

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.

  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]