【问题标题】:Dns add www prefix? [duplicate]dns加www前缀? [复制]
【发布时间】:2012-01-27 07:43:09
【问题描述】:

可能重复:
apache redirect from non www to www

是否可以配置DNS添加www。域名前缀?

Here is an example of this

【问题讨论】:

    标签: php apache dns


    【解决方案1】:

    DNS 响应包含域名到 IP 地址的映射。虽然您可以使用 CNAME 记录将 example.net 别名为 www.example.net,但这对用户来说是不可见的。

    您很可能希望 configure your web server to send an HTTP 301 redirect 访问正确的 URL。

    【讨论】:

      【解决方案2】:
      1. 您应该将 NS A 条目添加到 normalurl.com 和 www.normalurl.com 的 DNS 记录中
      2. 在 Apache 上启用 mod_rewrite 并创建一个包含以下条目的 .htaccess 文件:
      RewriteEngine On
      
      RewriteCond %{HTTP_HOST} !^www.normalurl.com$ [NC]
      RewriteRule ^(.*)$      http://www.normalurl.com/$1 [L,R]
      

      【讨论】:

      • .htaccess 不好。最好在 vhost 配置文件中添加一些 mod_alias 内容,以确保始终发生重定向/避免无限重定向循环等。另外,如果配置都在一个地方,那么读取配置要容易得多..
      • 如果您确实有权访问 vhost 配置,这是正确的;不过,这可能是许多共享托管环境的问题。
      【解决方案3】:

      不。您必须在yourdomain.com 配置网络服务器以重定向到www.yourdomain.com

      例如在apache上,可以使用这个配置(使用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>
      

      【讨论】:

        猜你喜欢
        • 2019-07-19
        • 1970-01-01
        • 2017-08-16
        • 2012-04-10
        • 2011-01-13
        • 2010-12-10
        • 2013-08-01
        • 2017-07-13
        • 2013-06-24
        相关资源
        最近更新 更多