【问题标题】:Subdomains with .htaccess (PHP)带有 .htaccess (PHP) 的子域
【发布时间】:2016-10-19 21:25:23
【问题描述】:

我希望在我的网站上创建一个 .htaccess 文件,以允许我输入“username.domain.com”作为 url,它会将我重定向到“http://domain.com/index.php?a=profile&u=username

例如:“john.domain.com”重定向到“http://domain.com/index.php?a=profile&u=john

谢谢

【问题讨论】:

标签: php .htaccess


【解决方案1】:

这不会进入 .htaccess,它会进入你的 httpd.conf 文件。看看这个问题:VirtualHost with wildcard VirtualDocumentRoot

您还需要为 *.example.com 设置通配符 dns 记录以指向您的服务器。在 PHP 中,通配符的 index.php 文件是这样的。

<?php
    $domain = "test.example.com";
    $domain_parts = explode(".", $domain);
    $username = $domain_parts[0];
    header("location: http://example.com/".$username);
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 2017-12-22
    • 2014-07-05
    • 2011-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多