RewriteRule 301 old domain to new domain with new urls

Hi.
I just can’t get my RewriteRule 301 to work as I want.
I don’t want to make fancy patterns, just tell the server that “this old url” is now “this new url on an other domain with an other url”.

Before I had two servers running Wordpress, one for english (.com) and one for Swedish (.se). After the switch to Kirby I now use the super nice Multilanguage feature to host both language on the .com domain. The site also got a complete new look and structure so a lot of the old urls does not exist or have new names/urls.

This is my .htaccess on the .se server (old domain):

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^$ http://www.new-domain.com/se? [R=301,L]
RewriteRule ^produkter/$ http://www.new-domain.com/se/produkter/? [R=301,L]
RewriteRule ^produkter/resolut-mrm-portal/$ http://www.new-domain.com/se/produkter/marketing-portal/marketing-portal? [R=301,L]

</IfModule>

When I go to www.old-domain.se/produkter/ or www.old-domain.se/produkter/resolut-mrm-portal/ I get an 404 instead for being redirected to the new url.

I have also tried to use Redirect 301 instead of RewriteRule:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^$ http://www.new-domain.com/se? [R=301,L]
Redirect 301 /produkter/ http://www.new-domain.com/se/produkter/
Redirect 301 /produkter/resolut-mrm-portal/ http://www.new-domain.com/se/produkter/marketing-portal/marketing-portal/

</IfModule>

This works a little bit. the First Redirect (/produkter/) works fine but mess upp the other. If I now go to www.old-domain.se/produkter/resolut-mrm-portal/ the server redirect me to http://www.new-domain.com/se/produkter/resolut-mrm-portal/ wish of course does not exist…

I just want a simple redirect… Hope some one can help.

If I recall correctly, the order of the redirects matter. Unless extremly specific, some redirects can conflict with others.

For example, /produckter/ will always match before /produkter/resolut-mrm-portal/ because it’s first in the list, unless your make your match stricter using RegEx.

Oh and I think your first line matches nothing. ^$ means Beginning of line and End of line with nothing in between.

I would try this.

<IfModule mod_rewrite.c>
RewriteEngine On

RedirectMatch 301 ^/?$ http://www.new-domain.com/se
RedirectMatch 301 ^/produkter/?$ http://www.new-domain.com/se/produkter
RedirectMatch 301 ^/produkter/resolut-mrm-portal/?$ http://www.new-domain.com/se/produkter/marketing-portal/marketing-portal

</IfModule>

I’m not 100% sure about the first RedirectMatch. You’d have to try it.

Thank you!
This works very well. Finally…

1 Like