The old domain initially had a permalink structure that goes domain1.com/%year%/%month%/%date%/%post-id%/post-title and while I changed the permalink structure to something simple domain1.com/post-title later on, the redirection was as simple as installing a redirection plugin.
But recently, the website migrated to a new domain; let's call it domain2.com. The following code has been added in .htaccess to redirect all old URLs to their corresponding URLs on new domain:
RewriteCond %{HTTP_HOST} ^domain1.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain1.com$
RewriteRule ^(.*)$ https://domain2.com/$1 [R=301,L]
This code works for most pages, except for the ones using old permalink structure.
The old permalink URLs are causing too many redirections (old domain name with old permalink structure -> old domain name with new permalink structure -> new domain name with new permalink structure), which I don't think is good for SEO.
The pages have good backlinks, and so the goal here is to pass on the value to the new domain.
Now, I understand that I can use this code for individual URLs (credit MrWhite)
RewriteCond %{HTTP_HOST} (w*)domain1\.com$ [NC]
RewriteRule ^2020/10/25/2257/title/?$ https://domain2.com/title/ [L,R=301]
But as that would involve adding in a lot of lines, I'm curious if this can be done with a generic piece of code -- old permalink URLs of old domain should redirect to the current permalink structure of new domain.
Both domains are hosted on the same server.