简体   繁体   中英

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM