I have an old domain (old.com) with plenty of dynamic urls and also static urls that are well positioned in google. I have a new domain (new.cat) where the same content has new urls more seo friendly.
The old.com site were in a IIS host, so I have transfered it to a server with apache, where I could use htaccess to redirect the old urls to the new ones. I have done it with php from the database in order to not to have writing every instruction by hand.
Examples dynamic old urls ==> new urls:
old.com/mots.asp?nm=1 ==> new.cat/moix old.com/mots.asp?nm=2 ==> new.cat/miol ...
Examples static old urls ==> new urls:
old.com/mesos.asp ==> new.cat/arxiu-cronologic old.com/mot_cerca_tema.asp?tipus=frases%20fetes ==> new.cat/tema/frases-fetes/ ...
Well, my .htaccess file has two kinds of rules:
Redirect 301 -> for static old urls (without parameters) ReweriteRule -> for dynamic old urls (with parameters)
These are the kind of rules (I have a lot more of them, but I only put someones in order to be clear. The "new.cat" is really filled with the httpp:// protocol)
Redirect 301 /mesos.asp new.cat/mots/arxiu-cronologic/
Redirect 301 /inici.asp new.cat/
Redirect 301 /mot_cerca.asp new.cat/mots/arxiu-cronologic/
RewriteEngine on
RewriteCond %{QUERY_STRING} ^nm=1$
RewriteRule ^mot.asp$ new.cat/moix/ [R=301,L]
RewriteCond %{QUERY_STRING} ^nm=2$
RewriteRule ^mot.asp$ new.cat/miol/ [R=301,L]
RewriteRule ^mot_cerca_resultat.asp$ new.cat/miol/ [R=301,L]
RewriteCond %{QUERY_STRING} ^nm=3$
RewriteRule ^mot.asp$ new.cat/gat-vell/ [R=301,L]
RewriteRule ^mot_cerca_resultat.asp$ new.cat/gat-vell/ [R=301,L]
#last rule for all the other dynamic urls
RewriteRule ^(.*)$ new.cat/$1 [R=301,L]
The problem is that the "redirect 301" rules are not executing, resulting in a 404 error because de rule executed is the last one.
For example:
old.com/mesos.asp results in new.cat/mesos.asp (that not exists in new.cat)
This problem occurs either if the "Redirect 301" rules are before the rewrite rules or after them.
If I put only the redirects 301 and not the others rules in the htaccess file, the redirects are executed correctly
So, anyone have any clue that could help me to resolve this problem? I suppose that there is some kind of preference problem, but I can't see why. I thought the problem could be because the .asp extension of urls, but if the rules work fine isolated or with rewriterule, it seems not a problem then.
The new site has wordpress as backend, and from there I can deal with 404 errors coming from the old.com and redirect them to an special page.
Thanks to all.