How to create subdomain for each language?

青春壹個敷衍的年華 提交于 2019-12-10 10:35:43

问题


I want to make website in multiple languages, I do it right with cookies to detect the user preferred language.

Now I want to make each language has its sub-domain to be indexed in search engines, some thing like Facebook.

so I want to configure my Apache to point all my virtual hosts to the same folder, then use $_SERVER["SERVER_NAME"] to figure out what sub-domain was requested.

I start to use this code in my htaccess file:

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

but it doesn't work and I get cannot find server when I request es.mydomain.come so any help ?

BTW I use mod_rewrite after that code above! and I didn't create any sub-domain in cPanel!


回答1:


You can direct all subdomains to the same folder using a wildcard *

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



回答2:


As long as your CNAME records are fine as BluesRock said

try this:

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

Another note to remember:

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


来源:https://stackoverflow.com/questions/9980957/how-to-create-subdomain-for-each-language

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