问题描述
do-main.de -> do-main.eu/de
do-main.at -> do-main.eu/de
do-main.cz -> do-main.eu/cs
do-main.sk -> do-main.eu/sk
do-main.pl -> do-main.eu/pl
do-main.be -> do-main.eu/nl
最后
domain.eu -> 域 main.eu
这是我尝试过的:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} \.cz$ [NC]
RewriteRule ^(.*)$ https://do-main.eu/cz [L,R=301]
RewriteCond %{HTTP_HOST} \.(at|de)$ [NC]
RewriteRule ^(.*)$ https://do-main.eu/de [L,R=301]
RewriteCond %{HTTP_HOST} \.sk$ [NC]
RewriteRule ^(.*)$ https://do-main.eu/sk [L,R=301]
RewriteCond %{HTTP_HOST} \.pl$ [NC]
RewriteRule ^(.*)$ https://do-main.eu/pl [L,R=301]
RewriteCond %{HTTP_HOST} \.be$ [NC]
RewriteRule ^(.*)$ https://do-main.eu/nl [L,R=301]
RewriteCond %{HTTP_HOST} ^\.do-main\.eu$ [NC]
RewriteCond %{HTTP_HOST} ^\.domain\.eu$ [NC]
RewriteRule ^(.*)$ https://do-main.eu [L,R=301]
</IfModule>
但它仅适用于 .de 和 .at 域(domain.eu 到 do-main.eu 也适用)。
有人可以帮我吗?
解决方法
您可以拥有以下 .htaccess 规则文件。请确保您的子域可用并且它们指向相同的文档根目录。
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^domain\.eu$ [NC]
RewriteRule ^ https://%do-main.eu%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} ^(do-main)(\.de|at)$ [NC]
RewriteRule ^ https://%1.eu/%2%{REQUEST_URI} [NE,L]
RewriteCond %{HTTP_HOST} ^(do-main)(\.cz)$ [NC]
RewriteRule ^ https://%1.eu/cs%{REQUEST_URI} [NE,L]
RewriteCond %{HTTP_HOST} ^(do-main)(\.sk|pl)$ [NC]
RewriteRule ^ https://%1.eu/%2%{REQUEST_URI} [NE,L]
RewriteCond %{HTTP_HOST} ^(do-main)(\.be)$ [NC]
RewriteRule ^ https://%1.eu/nl%{REQUEST_URI} [NE,L]
</IfModule>