I’ve looked all over this site and this question has been asked many times but never answered.
I found it easier to use a plugin called Redirection.
After the # END WordPress line you can simply do the following:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Replace domain.com with your website. This ensures that all requests sent to the old website should be redirected to the new domain.
P.S. this code should go in the htaccess of the old website and not the new one.
After the # END WordPress line
No. Always add additional rules BEFORE the WordPress block
Good point esmi. My bad there.
Thank you for your feedback.
The only issue with that solution is that I’ve pointed my new domain to the old domains location.
In the root directory I have a .htaccess file with this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.newdomain\.com)?$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
This works great.
It’s just the WordPress URLs that aren’t getting redirected because they go via the sub folder /news/ which is where the WordPress .htaccess file resides to rewrite the nice URLs.
You can write further URL rewrite rules to redirect old posts to the new posts, but if you do not have much posts, I would recommend you to use the “Permanent Redirect” rule in the htaccess file and make a rule for each URL.