在@anubhava的帮助下,我有一个很好的RewriteRule工作。
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
答案 0 :(得分:1)
您可以将第一个组设为捕获组,然后在后面引用中使用它:
RewriteCond %{HTTP_HOST} ^(www\.)?short\.(.+)$ [NC]
RewriteRule ^ http://%1longer.%2%{REQUEST_URI} [R=301,L,NE]