user2997418
user2997418

Reputation: 658

Redirect URLs from many subdomains using .htaccess

I am changing my website structure and I need to redirect 301 many URLs from many subdomains. I have many subdomains, How can I do that in one .htaccess ? Redirect both :

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

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

EDIT : Some URLs have folder and some have different name : exm :

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

Thank you

Upvotes: 1

Views: 23

Answers (1)

anubhava
anubhava

Reputation: 786359

You may use these redirect rules:

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]

Upvotes: 1

Related Questions