The situation:

  1. An old WordPress website has been replaced by a new WordPress
    multisite (ROOT, nl, en) and the links have changed.
  2. I want to redirect the traffic coming in from the old URLs to the new URLs (eg. /cases –> /nl/blog)

The rule set:

URI is empty         --> redirect to /nl (default language)
URI is /en OR /nl    --> redirect to /en/ OR /nl/ (add forward slash)

URI is /oldurl1      --> redirect to /newurl1
URI is /oldurl2      --> redirect to /newurl2
...
URI is /oldurlX      --> redirect to /newurlX

URI is NOT ANY of the known old URLs or new ones --> show nl/404

Without the last line, the default WordPress 404 doesn’t show up, but instead the browser 404 comes up.


Trial and failiure:

RewriteEngine On
RewriteBase /


# URI is empty --> redirect to /nl (default language)
RewriteRule ^$ nl/ [R=301,L]

# URI is /en OR /nl --> redirect to /en/ OR /nl/ (add forward slash)
RewriteRule ^(en|nl)$  $1/ [R=301,L]

# URI is /oldurl1 --> redirect to /newurl1
RewriteRule ^(oldurl1|oldurl1/)$  nl/newurl1/ [R=301,L]

# URI is NOT ANY of the known old URLs or new ones --> show nl/404
RewriteRule !^(nl|en|nl/|en/|oldurl1|oldurlX......this can't be right)$  nl/404

The question

What would be an efficient way of directing all unknown URLs to the 404 page?

Read more here: Htaccess RewriteRule if none of the following


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: