问题
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
回答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>
回答2:
- You should add a NS A entry to the DNS record for both normalurl.com and www.normalurl.com
- 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]
回答3:
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.
来源:https://stackoverflow.com/questions/8624663/dns-add-www-prefix