Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php htaccess通过删除点从多个子域重定向_Php_Apache_.htaccess_Redirect_Cakephp - Fatal编程技术网

Php htaccess通过删除点从多个子域重定向

Php htaccess通过删除点从多个子域重定向,php,apache,.htaccess,redirect,cakephp,Php,Apache,.htaccess,Redirect,Cakephp,我需要在.htaccess中重定向一组子域。我不擅长正则表达式,也没能理解我读过的其他帖子,因此无法将其应用于这种情况 我的网站布局如下: quark.subdomain.site.com yy.subdomain.site.com bit.subdomain.site.com etc 其中,子域可以是任何内容,但子域始终相同 我需要将它们重定向到: quarksubdomain.site.com yysubdomain.site.com bitsubdomain.site.com etc

我需要在.htaccess中重定向一组子域。我不擅长正则表达式,也没能理解我读过的其他帖子,因此无法将其应用于这种情况

我的网站布局如下:

quark.subdomain.site.com
yy.subdomain.site.com
bit.subdomain.site.com
etc
其中,子域可以是任何内容,但子域始终相同

我需要将它们重定向到:

quarksubdomain.site.com
yysubdomain.site.com
bitsubdomain.site.com
etc
所以基本上,我只需要去掉这个点

我能用这个问题的答案走到这一步:

但这是对每个子域分别进行的:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^quark.subdomain\.(.+)$ [NC]
RewriteRule ^ https://quarksubdomain.%1 [L,R=301]

RewriteCond %{HTTP_HOST} ^yy.subdomain\.(.+)$ [NC]
RewriteRule ^ https://yysubdomain.%1 [L,R=301]
但我有30个左右的子域,所以我想要更有效的

1) 是否有一种通配符方法可以用于从子域的任何子域中删除点

2) 我无法传递domain.com/之后的地址的任何部分。我使用的是CakePHP,所以请求URI不起作用,因为它提供了Cake隐藏的地址信息。不使用请求URI的最好方法是什么


为初学者解释正则表达式特殊字符的链接获得额外积分。我想纠正我的无知。

您不需要从条件中获取请求URI,您可以从重写规则中获取if,并优化从条件中保留的内容:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.subdomain\.site\.com$ [NC]
RewriteRule (.+) https://%1subdomain.site.com$1 [L,R=301]

加分。。。我不知道,也许吧?

经过一些尝试和错误,我终于在以下方面取得了成功:

RewriteCond %{HTTP_HOST} ^(.+)\.subdomain\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%subdomain.%2/$1 [QSA,L,R=301]
它正确地获取任何前缀并将其附加到子域名,还正确地传递.com/后面的位置。我还使它对域不敏感,因此它在我的开发域上也能正常工作


不过,我不能给自己任何加分,因为我仍然无法解释为什么要这样才能通过特定的页面地址。

对不起,我应该更清楚一些。“quark1等”可以是任何东西。我需要使用通配符前缀,并将其传递给重写规则。我将编辑我的帖子以增加清晰度。我编辑了我的答案,如果域的结尾总是一样的话,这不会有多大变化。出于某种原因,该代码对我不起作用。它似乎与重写条件不匹配。我明天会玩一玩,看看是不是我做得不对。我来看看Regexone的练习。