I need to combine multiple redirects via my .htaccess in Wordpress for future site migration and re-launch:

  • Domain change
  • Force HTTPS
  • Force www
  • URL structure changes (important to keep juice here)

I'm wondering if there's any order this is preferably done? Page to page redirects before or after domain and HTTPS+www? Does it matter? And is the below code correct?

RewriteEngine On

# Force HTTPS, WWW URLs, and change of domain
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^ https://www.newdomain.com%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

## 301 Redirects
# Page to Page
Redirect 301 pages/page-name https://www.newdomain.com/page-name
Redirect 301 collections/products/product-1 https://www.newdomain.com/product/product-1

# BEGIN WordPress

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress
  • How many URL changes (redirects) are there? Is there a discernable pattern in these redirects? Any intention to implement HSTS?
    – MrWhite
    Mar 11, 2021 at 1:09
  • There are about 150 redirects. Regular pages will follow the same pages/page-name >> newdomain.com/page-name pattern, and for some of the products collections/product-category/products/product-name >> newdomain.com/product/product-name. There isn't a noticeable pattern for all redirects though. We'll have a Let's Encrypt Certificate, I think Siteground supports HSTS. How would you go about implementing it in this situation?
    – Lalie
    Mar 11, 2021 at 1:56
  • The target URLs above were transformed into Hyperlinks by the editor, but they do start with 'www.'
    – Lalie
    Mar 11, 2021 at 1:57

1 Answer 1


You've definitely got the right idea, and yes, page-to-page first.

Do the page-to-page redirects first and use the absolute correct URL. That way, anyone hitting a page that has to be redirected will bypass the other steps because they don't meet the conditions.

Your reference to keeping the juice means that these page-to-page redirects are the most important to you, so make sure they're done first and done right. None of these will then have more than one redirect.

Then do the old => new domain redirect and the force HTTPS that you have already, in the order you already have them. This will pick up any traffic not hitting a page-to-page redirect and will still only redirect once.

Doing it the other way around means anyone coming to an old page on the new site (which is possible) would hit multiple redirects, and that's something to try to avoid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.