Home Avoiding double 301 redirects in two stage migration
Reply: 0

Avoiding double 301 redirects in two stage migration

James
1#
James Published in 2017-11-13 17:09:44Z

A few months ago, I migrated a client website from an old legacy CMS to Wordpress. Many URLs changed, which I 301 redirected in .htaccess - all seemed well. This was all http, no https, which brings me to ...

Today, I migrated the client onto https and have run into issues with the redirects. Those old URLs are now going through 2x redirects, once to change the URL to https and then again to go the new site URL. I'm not sure how to set up the .htaccess file so those old site http URLs go directly to the new site https URLs, without the unwanted middle step.

I've read that the problem is probably me muddling re-writes and re-directs. I wonder if the Wordpress re-write bit is involved too.

Here's what I've got, with just 2 example URLs to keep it as brief as possible. I've added comments after the # to try and explain my thinking:

Options +FollowSymLinks
RewriteEngine on

# these two lines, I hoped, would redirect from the previous site's http URL to the new site's https URL - but in practice, it is being ignored and it seems to skip to the site-wide rule below it
Redirect 301 /page1 https://www.example.com/folder/page1/
Redirect 301 /page2 https://www.example.com/folder/page2/

# this is the site-wide re-write of new site non-https requests to https - this works fine
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# This is the standard Wordpress rules, this might be impacting what I'm trying to do
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I hope it's clear what I'm trying to do. I think the solution is using all re-writes, and putting them in the correct order, possibly within the Wordpress bit?

Thanks in advance for any help.

Jim

EDIT (sorry for trying to put this in comments). Following the helpful suggestion, I now have this:

This is what I'm doing now:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off
RewriteRule ^/page1$ https://%{HTTP_HOST}/folder/page1/ [R=301,L]
RewriteRule ^/page2$ https://%{HTTP_HOST}/folder/page2/ [R=301,L]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

But this line: RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] is not working to redirect any other URLs to https

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301187 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO