Reputation: 1205
I have a old domain with a old url structure and want redirect (301) it to an another domain with a new url-structure. I have urls that must be transform individually:
http://domainA.com/ => http://ru.domainB.com/ http://domainA.com/?fieldA=abc => http://ru.domainB.com/xxx/zzz http://domainA.com/?fieldA=www&fieldB=aaa => http://ru.domainB.com/uuu/ooo/ppp
another urls have the same values:
http://domainA.com/?fieldC=abc&fieldD=4 => http://ru.domainB.com/abc/xxx/4 http://domainA.com/?fieldC=abc&fieldD=5 => http://ru.domainB.com/abc/xxx/5 http://domainA.com/?fieldC=abc&fieldD=6 => http://ru.domainB.com/abc/xxx/6 http://domainA.com/?fieldC=def&fieldD=4 => http://ru.domainB.com/def/xxx/4 http://domainA.com/?fieldC=def&fieldD=5 => http://ru.domainB.com/def/xxx/5 http://domainA.com/?fieldC=def&fieldD=6 => http://ru.domainB.com/def/xxx/6
left side urls can have optional "index.php" before "?" or "www." before domain name. Can anybody help me here and translate this 4 links with mod_rewrite(apache), please?
My account have multiple domain-names for one webspace (wildcard subdomains). Pseudo setting in apache conf:
ServerAlias *.domainA.com ServerAlias *.domainB.com ServerAlias *.domainC.com ServerAlias *.domainD.com
EDIT: This helps me.
RewriteCond %{HTTP_HOST} ^(www\.|)domainA\.com RewriteCond %{QUERY_STRING} fieldA=xxx) RewriteRule ^(.*)$ http://ru.domainB.com/? [R=301,L] RewriteCond %{HTTP_HOST} ^(www\.|)domainA\.com RewriteCond %{QUERY_STRING} fieldA=abc RewriteRule ^(.*)$ http://ru.domainB.com/abc/bbb/? [R=301,L] RewriteCond %{HTTP_HOST} ^(www\.|)domainA\.com RewriteCond %{QUERY_STRING} fieldA=abc&fieldB=(\d+) RewriteRule ^(.*)$ http://ru.domainB.com/abc/%1? [R=301,L]
Upvotes: 0
Views: 236
Reputation: 24478
What about doing just a redirect 301 in your .htaccess file?
redirect 301 http://domainA.com/ http://ru.domainB.com/
Update: if you need all 4 of your URLS and they are very specific like you said. Then try this.This should work for all 4 of the URLS.
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)fieldA=abc(&|$) [NC]
RewriteRule ^(.*)$ http://ru.domainB.com/xxx/zzz? [R=301,L,NC]
RewriteCond %{QUERY_STRING} (^|&)fieldA=www&fieldB=aaa(&|$) [NC]
RewriteRule ^(.*)$ http://ru.domainB.com/uuu/ooo/ppp? [R=301,L,NC]
RewriteCond %{QUERY_STRING} (^|&)fieldC=abc&fieldD=4(&|$) [NC]
RewriteRule ^(.*)$ http://ru.domainB.com/abc/xxx/4? [R=301,L,NC]
RewriteRule ^(.*)$ http://ru.domainB.com/$1 [R=301,L,NC]
Update 2:
Try this for the new URL's then. This will match fieldC and fieldD with either ABC
or DEF
.
RewriteCond %{QUERY_STRING} ^fieldC=(.*)&fieldD=(.*) [NC]
RewriteRule ^(.*)$ http://ru.domainB.com/%1/xxx/%2 [R=301,L,NC]
Upvotes: 1