带有 php/ htaccess 的动态子域

发布于 2024-09-19 07:58:09 字数 404 浏览 1 评论 0原文

基本上,我想做的是:

  1. 将child.domain.com更改为domain.com/child

  2. 但是,我已经在htaccess中有一个ReWriteRule将domain.com/child 更改为domain.com?page=child。当然,在htaccess中,我还有一个重写条件来忽略实际的文件夹和文件。但是,如果我为子域创建一个子域,服务器实际上会为子域创建一个物理文件夹,因此domain.com/child将被RewriteRule完全忽略。

  3. 所以如果可能的话,我想将child.domain.com直接更改为domain.com?page=child

这是可以通过 htaccess 实现的还是我必须在我的 cpanel 中设置子域?

Basically, what i wanna do :

  1. change child.domain.com to domain.com/child

  2. However, I already have a ReWriteRule in htaccess to change domain.com/child to domain.com?page=child. Of course, in htaccess, I also have a rewrite condition to ignore actual folders and files. But if i create a subdomain for child, the server will actually create a physical folder for child, thus domain.com/child will be ignored by the RewriteRule completely.

  3. So if possible, I want to change child.domain.com straight into domain.com?page=child

Is this achievable through htaccess or I must set the subdomains in my cpanel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

标点 2024-09-26 07:58:09

您必须配置子域,以便它能够正确响应 dns 查询。您可以使子域解析到同一服务器。

重写规则按照它们在配置文件中出现的顺序进行处理,您可以将 [L] 附加到规则末尾以控制是停止处理还是继续应用更多规则。

使用 RewriteCond 来匹配主机名(以下 RewriteRule 仅在满足 RewriteCond 时才匹配:

RewriteCond %{HTTP_HOST} subdomain.domain.com
RewriteRule ^/(.*) http://domain.com/?page=subdomain&$1 [L]

You must configure the subdomain so that it will respond correctly to dns queries. You can make the subdomain resolve to the same server.

Rewrite rules are processed in the order they appear in your config file and you can append [L] to the end of the rule to control whether to stop processing or to keep applying further rules.

Use RewriteCond to match against the hostname (the following RewriteRule only matches if RewriteCond is met:

RewriteCond %{HTTP_HOST} subdomain.domain.com
RewriteRule ^/(.*) http://domain.com/?page=subdomain&$1 [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文