【问题标题】:How to create dynamic subdomains with .htaccess? [duplicate]如何使用 .htaccess 创建动态子域? [复制]
【发布时间】:2012-12-17 19:21:49
【问题描述】:

可能重复:
Create Subdomains on the fly with .htaccess (PHP)

我希望使用 .htaccess 获得以下域结构:

domain.com        REWRITES TO   Home Page (index.php)

www.domain.com    REWRITES TO   Home Page (index.php)

blog.domain.com   REWRITES TO   index.php?page=blog

*.domain.com      REWRITES TO   index.php?page=user&id=* (where * can be anything)

有没有办法创建这样的东西?

【问题讨论】:

  • 查看this link. 这是另一个像你一样的问题,答案很好。

标签: php apache .htaccess


【解决方案1】:

您还没有说明您希望重写使用哪个主机名,所以我假设 www 子域

RewriteCond %{HTTP_HOST} ^([w]{3,3}[.]{1,1}){0,1}domain.com$
RewriteRule ^$ http://www.domain.com/index.php [R,L]

RewriteCond %{HTTP_HOST} ^blog.domain.com$
RewriteRule ^.*$ http://www.domain.com/index.php?page=blog [R,L]

RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}domain.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]domain.com$
RewriteRule ^.*$ http://www.domain.com/index.php?page=user&id=%1 [R,L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 2012-07-11
    • 2016-04-14
    相关资源
    最近更新 更多