【问题标题】:How to create subdomain for each language?如何为每种语言创建子域?
【发布时间】:2012-04-16 09:08:09
【问题描述】:

我想制作多种语言的网站,我使用 cookie 来检测用户的首选语言。

现在我想让每种语言都有它的子域,以便在搜索引擎中被索引,比如 Facebook。

所以我想将我的 Apache 配置为将我的所有虚拟主机指向同一个文件夹,然后使用 $_SERVER["SERVER_NAME"] 来确定请求的子域。

我开始在我的 htaccess 文件中使用此代码:

<VirtualHost *>
    ServerName mydomain.com
    ServerAlias en.mydomain.com ar.mydomain.com es.mydomain.com
</VirtualHost>

但它不起作用,当我请求 es.mydomain.come 时我找不到服务器所以有什么帮助吗?

顺便说一句,我在上面的代码之后使用了 mod_rewrite!而且我没有在 cPanel 中创建任何子域!

【问题讨论】:

    标签: php apache subdomain virtualhost


    【解决方案1】:

    只要您的 CNAME 记录像 BluesRock 所说的那样好

    试试这个:

    <VirtualHost *:80>
      DocumentRoot /www/public //whatever the root is!
      ServerName domain.com
      ServerAlias en.domain.com, es.domain.com
    </VirtualHost>
    

    要记住的另一个注意事项:

    $_SERVER["SERVER_NAME"]//will always show domain.com
    $_SERVER["HTTP_HOST"]//Will show en.domain.com if that is where they entered from.
    

    【讨论】:

      【解决方案2】:

      您可以使用通配符 * 将所有子域定向到同一文件夹

      <VirtualHost *>
            ServerName mydomain.come
            ServerAlias *.mydomain.com
      </VirtualHost>
      

      【讨论】:

      • 错误消息“找不到服务器”很可能是 DNS 问题。如果您使用的是 Windows,请在命令行中键入“nslookup”,然后键入问题域名。如果您得到一个具有有效 IP 地址的非权威答案,那么它就可以工作,但如果您得到“不存在的域”,那么这是一个 DNS 问题。请注意,DNS 更改需要 24 小时以上才能生效。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多