简体   繁体   English

将网址子域重定向到子目录

[英]Redirect Url sub-domain to sub-directory

I am trying to redirect url. 我正在尝试重定向url。 When someone type xyz.example.com then its redirected to example.com/zyz . 当有人键入xyz.example.com其重定向到example.com/zyz I have No sub-domain. 我没有子域。 I am trying when someone enters exact string xyz.example.com then redirect to example.com/xyz . 我正在尝试当有人输入确切的字符串xyz.example.com然后重定向到example.com/xyz I am working on multi networking site. 我在多网站上工作。

xyz.example.com

This is not existing Domain . 这不是现有的Domain。

example.com/xyz 

This is multi-networking site url no sub-domain existing for this 这是多网络站点网址,为此没有子域

You will have to configure an apache virtual host. 您将必须配置apache虚拟主机。

<VirtualHost *:80>
    DocumentRoot "/www/subdomainFolder"
    ServerName subdomain.example.com

    # Other directives here
</VirtualHost>

In the other hand if you have a wildcard * IN A 192.0.2.1 to map all subdomains to your primary domain ip. 另一方面,如果您有通配符* IN A 192.0.2.1可以将所有子域映射到您的主域ip。 You may: 你可以:

<?php
   $hotsname = $_SERVER["HTTP_HOST"];
   $arr = explode('.',$hostname);
   $url='http://example.com/';
   if(count($arr)>2){
      // we have a subdomain

      // redirect xyz only.
      if($arr[0] == "xyz"){
          header("location:" $url. $arr[0]);
          exit();
      }
   }

   // Continue normal operation, no redirect.

?>

Apache VirtualHost Documentation Apache VirtualHost文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM