【问题标题】:Allow dynamic subdomain in url using htaccess使用 htaccess 在 url 中允许动态子域
【发布时间】:2016-02-02 07:50:18
【问题描述】:

我为我的站点创建了一个虚拟主机 www.maindomain.com。我想允许使用 htaccess 的 url 中的动态子域,即应该允许 test.maindomain.com、abc.maindomain.com 等。我的站点文件夹结构是 www/test/index.php。

这是我当前的 htaccess 代码:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z]+)\.maindomain\.com$ [NC]
RewriteRule .? index.php?url=%1&path=%{REQUEST_URI} [L,QSA]    
</IfModule>

我得到 Server not found and could not connect 错误消息。

谁能建议我解决这个问题的好方法?

提前致谢!

【问题讨论】:

  • 这些子域需要先注册

标签: .htaccess subdomain


【解决方案1】:

如果您的服务器在线:

您的虚拟主机中需要一个Wildcard DNS record 和一个通配符serverAlias

<VirtualHost *:80>
    ServerAdmin admin@example.local
    DocumentRoot "/my_server/htdocs"
    ServerName example.local
    ServerAlias *.example.local
    # [...]
</VirtualHost>

最后,您将能够在 .htaccess 文件中捕获这些子域。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-17
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    • 2013-12-08
    • 2019-02-11
    • 2013-05-29
    • 2014-05-22
    相关资源
    最近更新 更多