make all subdomains access website root files

五迷三道 提交于 2020-02-01 09:15:06

问题


Here's what I want to do:

  • 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.

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 .


回答1:


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>

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



来源:https://stackoverflow.com/questions/6490512/make-all-subdomains-access-website-root-files

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