htaccess wildcard redirect misses some URLs

You’ve put the redirect directive in the wrong place. It needs to go before the WordPress front-controller, otherwise, the redirect will simply get ignored for anything other than URLs that map directly to the filesystem.

Since these domains are also on the same server (same hosting account I assume) then you will need to check for the requested hostname, otherwise, you’ll get a redirect loop.

For example:

# Redirect everything from old to new domain
RewriteCond %{HTTP_HOST} ^old\.example [NC]
RewriteRule (.*) https://new.example/$1 [R=301,L]

# BEGIN WordPress
# :

The regex ^(.*)$ can be simplified to (.*) since regex is greedy by default.

Leave a Comment

error code: 523