【问题标题】:htaccess for subdomain to the main domainhtaccess 子域到主域
【发布时间】:2013-01-07 16:15:45
【问题描述】:

我们正在尝试为我们的网站创建 .htaccess 重定向,这是我们想要做的:

我们的域名: http://freewebsites.com

我们希望将所有访问http://freewebsites.com/username 的用户重定向到http://username.freewebsites.com/

这应该适用于访问该网站的任何人。所以,我们不需要索引文件什么的。

【问题讨论】:

    标签: apache redirect subdomain


    【解决方案1】:

    最好的方法是使用带有 GET 变量的 PHP

    创建一个名为 index.php 的页面并将此代码放入其中

    <?php
    // check to see if Variable 'Username' is sent to it
    if(isset($_GET["Username"])){
    // if sent set User var
    $user = $_GET["Username"];
    //Send user to domain
    header("Location: http://$user.freewebsites.com");
    
    }else{
    // if not send back to main domain
    header("Location: http://freewebsites.com");
    }
    ?>
    

    如果您将用户发送到 URL,则使用它

    http://freewebsites.com/index.php?Username=TestUser
    

    将发送到

    http://TestUser.freewebsites.com
    

    【讨论】:

      猜你喜欢
      • 2014-07-25
      • 2016-07-06
      • 1970-01-01
      • 2016-12-29
      • 2016-02-06
      • 1970-01-01
      • 2015-06-03
      • 2013-06-16
      • 1970-01-01
      相关资源
      最近更新 更多