使用 .htaccess 从许多子域重定向 URL

Redirect URLs from many subdomains using .htaccess

我正在更改我的网站结构,我需要重定向来自许多子域的 301 个 URL。 我有很多子域,如何在一个 .htaccess 中做到这一点? 重定向两者:

ch.mydomain.com/coffeewww.mydomain.com/de_ch/coffee

it.mydomain.com/coffeewww,mydomain.com/it_IT/coffee

编辑: 有些 URL 有文件夹,有些有不同的名称: 例如:

ch.mydomain.com/coffetype/nespressowww.mydomain.com/de_ch/nespressocafe

谢谢

您可以使用这些重定向规则:

RewriteEngine On

# specific rules
RewriteCond %{HTTP_HOST} ^ch\. [NC]
RewriteRule ^coffetype/nespresso/?$ http://example.com/de_ch/nespressocafe [L,NC,R=301]

# generic rules that have same URIs after redirect

RewriteCond %{HTTP_HOST} ^ch\. [NC]
RewriteRule ^ http://example.com/de_ch%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{HTTP_HOST} ^it\. [NC]
RewriteRule ^ http://example.com/it_IT%{REQUEST_URI} [L,NE,R=301]