使用 .htaccess 从许多子域重定向 URL
Redirect URLs from many subdomains using .htaccess
我正在更改我的网站结构,我需要重定向来自许多子域的 301 个 URL。
我有很多子域,如何在一个 .htaccess 中做到这一点?
重定向两者:
ch.mydomain.com/coffee 至 www.mydomain.com/de_ch/coffee
it.mydomain.com/coffee 到 www,mydomain.com/it_IT/coffee
编辑:
有些 URL 有文件夹,有些有不同的名称:
例如:
ch.mydomain.com/coffetype/nespresso 至 www.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]
我正在更改我的网站结构,我需要重定向来自许多子域的 301 个 URL。 我有很多子域,如何在一个 .htaccess 中做到这一点? 重定向两者:
ch.mydomain.com/coffee 至 www.mydomain.com/de_ch/coffee
it.mydomain.com/coffee 到 www,mydomain.com/it_IT/coffee
编辑: 有些 URL 有文件夹,有些有不同的名称: 例如:
ch.mydomain.com/coffetype/nespresso 至 www.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]