Apache 如何使该规则子域不可知?

Apache 如何使该规则子域不可知?,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,在我的帮助下,我有了这个很好的重写规则 short.dev redirects to longer.dev short.com redirects to longer.com 使用此选项: RewriteCond %{HTTP_HOST} ^(?:www\.)?short\.(.+)$ [NC] RewriteRule ^ http://longer.%1%{REQUEST_URI} [R=301,L] 我现在需要扩展此规则,使其也成为子域不可知的-如: www.short.dev r

在我的帮助下,我有了这个很好的重写规则

short.dev  redirects to longer.dev
short.com  redirects to longer.com
使用此选项:

RewriteCond %{HTTP_HOST} ^(?:www\.)?short\.(.+)$ [NC] 
RewriteRule ^ http://longer.%1%{REQUEST_URI} [R=301,L]
我现在需要扩展此规则,使其也成为子域不可知的-如:

www.short.dev redirects to www.longer.dev
www.short.com redirects to www.longer.com

es.short.dev redirects to es.longer.dev
es.short.com redirects to es.longer.com

您可以将第一个组设为捕获的组,然后在后面的引用中使用它:

RewriteCond %{HTTP_HOST} ^(www\.)?short\.(.+)$ [NC] 
RewriteRule ^ http://%1longer.%2%{REQUEST_URI} [R=301,L,NE]

如果你有时间,请检查一下这个好吗。谢谢