Dns add www prefix? [duplicate]

大城市里の小女人 提交于 2019-12-13 07:17:13

问题


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:


  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]



回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!