使所有子域访问网站根文件 [英] make all subdomains access website root files

查看:90
本文介绍了使所有子域访问网站根文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想做的事情:


  • 假设我有www.mysite.com,这是一个包含大量文件的复杂网站

  • 我要创建fr.mysite.com,it.mysite.com,uk.mysite.com来访问根网站中的文件(即:fr.mysite.com/jobs .php实际上会加载mysite.com/jobs.php,但在浏览器的url中将显示带有子域的链接。)

  • 我想建立一个包含来自多个国家/地区的内容的网站,希望将每个国家/地区的代码作为子域进行访问。如果可以的话,我可以在php中处理该网址,并知道该网址中包含哪个国家/地区代码。

  • 将整个网站复制到每个子域文件夹是不可行的。
  • li>
  • Let's say i have www.mysite.com and it's a complex website with alot of files
  • I want to make fr.mysite.com, it.mysite.com, uk.mysite.com to access the file in the root website (ie: fr.mysite.com/jobs.php will actually load mysite.com/jobs.php but in the browser url it will show the link with subdomain).
  • I want to build a site with content from multiple countries and I want each country to be accessed with it's code as a subdomain. If I can do that I can then process the url in php and know what country code it's in the url.
  • Copying the entire site to each subdomain folder isn't an option.

让我知道您是否对此有任何想法,我想这是一个.htaccess的问题,但我不知道。

Let me know if you have any idea on how to do that, I guess it's a .htaccess thingy but I can't figure it out .

推荐答案

VistualHost中使用 ServerAlias 配置:将其设置为单个虚拟主机,其中所有子域都指向同一根文件夹:

Use ServerAlias in your VistualHost configuration: set it up as single virtual host where all sub-domains point into the same root folder:

<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias *.mysite.com
    DocumentRoot "\path\to\your\site\"
    ...
</VirtualHost>

这是最推荐的方式-无需在此处进行URL重写。

This is the most recommended way -- no need to involve URL rewrite here.

这篇关于使所有子域访问网站根文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆