使用.htaccess重定向来自多个子域的网址

问题描述 投票:1回答:1

我正在更改我的网站结构,我需要从许多子域重定向301多个URL。我有很多子域名,我怎么能在一个.htaccess中做到这一点?重定向:

ch.mydomain.com/coffee到www.mydomain.com/de_ch/coffee

it.mydomain.com/coffee到www,mydomain.com / it_IT / coffee

编辑:有些网址有文件夹,有些网址有不同的名称:exm:

ch.mydomain.com/coffetype/nespresso到www.mydomain.com/de_ch/nespressocafe

谢谢

apache .htaccess url-rewriting dns subdomain
1个回答
1
投票

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

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]
© www.soinside.com 2019 - 2024. All rights reserved.