【问题标题】:Wildcard subdomain doesn't include subfolders通配符子域不包括子文件夹
【发布时间】:2020-05-18 16:04:01
【问题描述】:

在 cPanel(在子域管理中)我设置了一个通配符,如下所示:

*.example.com > public_html/subDomainHandler

abc.example.com 这样的每个(不存在的子域)请求都会正确重定向到example.com/subDomainHandler

但是像abc.example.com/subfolder 这样的请求不会重定向到example.com/subDomainHandler

我在正则表达式方面不是最好的,但谁能给我一个 .htaccess 的 RewriteCondition 吗?

【问题讨论】:

  • 这些规则是否被写入 .htaccess 文件?
  • 是的,它们可以用 htaccess 编写。
  • 这里应该没有“重定向”;你的意思是“解决”?或者您是否专门在 cPanel 中设置了子域“重定向”?像abc.example.com/subfolder 这样的请求应该解析example.com/subDomainHandler/subfolder 而不需要做任何额外的事情吗?它在哪里解析(或“重定向”?)到?
  • 应该解决。抱歉打错了。

标签: .htaccess subdomain cpanel


【解决方案1】:

Htaccess 重写规则 - Try1

我认为你的答案可以仿照https://stackoverflow.com/a/8481076/1688441

尝试以下方法:

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com\(.*)
RewriteRule ^(.*)$ http://example.com/subDomainHandler/$1 [R=301]

试试2

另一种选择:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com [NC]
RewriteRule (.*) http://www.example.com/subDomainHandler%1 [R=301,L]

发件人:https://webmasters.stackexchange.com/questions/13475/redirect-rewrite-subdomain-to-subfolder

【讨论】:

  • 因此,在设置通配符域时,请确保同时为该(通配符)域安装 SSL。有时,“老派思维”包括一个(小)差距。
  • 没有。但我很快会在另一台服务器上测试它。正如我所说,缺少的 SSL 正在探测地阻止正则表达式的(正确?)结果..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-14
  • 2014-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-27
  • 1970-01-01
相关资源
最近更新 更多