【问题标题】:.htaccess Dynamic sub domains.htaccess 动态子域
【发布时间】:2014-05-22 21:06:38
【问题描述】:

我想要动态子域,例如: (.*).mydomain.com

我可以用$_GET['subdomain'] 检索。我添加了一条通配符 DNS 记录 (* A xx.xx.xx.xx),现在对于我访问的每个子域(例如 test.mydomain.com),我得到的只是:

Apache is functioning normally

我在 .htaccess 中尝试过这段代码,但似乎没有任何帮助:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$
RewriteRule ^(.*)$    http://www.mydomain.com/?subdomain=%1 [L]

提前致谢!

【问题讨论】:

    标签: php .htaccess dns rewrite subdomain


    【解决方案1】:

    您是否正在寻找类似的东西?

    RewriteCond %{QUERY_STRING} !subdomain=
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$ [NC]
    RewriteRule ^(.*)$ /$1?subdomain=%1 [L,QSA]
    

    【讨论】:

    • 我没有得到正常的主页,我仍然得到Apache is functioning normally,所以它并没有像我希望的那样工作。
    • @ArkoElsenaar 并且您已将服务器设置为接受来自 *.mydomain.com 的请求?它需要别名,否则默认虚拟主机将处理这些请求中的所有
    • prntscr.com/38fa10 - 这是我添加到我的 DNS 的内容,我还需要检查什么?
    • @ArkoElsenaar 你需要检查你的 apache 设置,(这就是我所说的“服务器”)。 Apache 必须知道,当它收到对主机“blahblah.mydomain.com”的请求以提供与“www.mydomain.com”相同的站点时。它不会自动发生。
    • 我如何确保它服务于同一个网站?
    猜你喜欢
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 2011-03-30
    • 2013-11-19
    • 1970-01-01
    相关资源
    最近更新 更多