Impacts on backlinks: https, www, 301 Redirects

I am in the process of rebuilding a large (over 175 pages) RW website with a new theme and better mobile responsiveness. The basic structure of the site will remain the same.

The current site has over 2,000 backlinks. Of course, I’m hoping these won’t be lost during the update. The vast majority of these backlinks are tidylinks, so a change from the HTML extension to PHP shouldn’t be a big problem.

My concern is that a change from http://mysite.com to a more secure https://mysite.com could impact these backlinks. Also, many of the backlinks refer to www.mysite.com/example/ instead of simply mysite.com/example/.

It appears that some 301 Redirects will be necessary to preserve my backlinks. Any suggestions as to the best way to write/structure these 301 Redirects would be sincerely appreciated.

You might have a look at this post.

The first example will redirect HTTP to HTTPS and redirect any www to the non-www URL’s.

This assumes you’re using Apache and have access to the htaccess file on your host.

Now if any of the old pages are being renamed or are going away then you’ll need to have some rewrite rules for those individually.

Hi Doug,

Thank you so much for your knowledgeable assistance. I have tested some relevant htaccess rewrite rules using https://htaccess.madewithlove.be/. There is both good news and bad news. Here are the results.

EXAMPLE 1 (successful)

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

http://mysite.com/ resolves to https://mysite.com/

and

http://www.mysite.com/ resolves to https://mysite.com/

EXAMPLE 2 (successful)

RewriteEngine On
RewriteRule ^A.* /B[R=301]

http://mysite.com/A/ resolves to http://mysite.com/B[R=301]

EXAMPLE 3 (successful)

Redirect 301 /A/ /B/

http://mysite.com/A/ resolves to http://mysite.com/B/

HOWEVER, if I try to use the rules in EXAMPLE 1 with those of EXAMPLE 2 or EXAMPLE 3, only EXAMPLE 1 produces the proper result. Do you know why the rules in EXAMPLE 1 seem to be incompatible with the others? This is important as I have many URLs that need to be redirected.

Best regards,

Gerald

If I understand what you’re examples are, I believe what you are seeing is a limitation of the made with love tester.

The tester will stop as soon as it gets a redirect, much like the real htaccess file does.
You’ll see this message when made with love ends it’s testing

Test are stopped, a redirect will be made with status code 301

The difference is in the real website when the redirect happens, it should “come back” to the htaccess file and make another pass with the new URL.
Made with love limits testing to a single pass.

So in your example 2
http://mysite.com/A/
Would get changed to
https: by the first rule,
And then the new https://mysite.com/A/ would then go through the same htaccess file. Since the new URL already is https and doesn’t have www at the start the first rewrite condition will not get met so it would processed to the next rule.

You can and should test these on a live htaccess file. Just change the 301’s to 302’s until you’re satisfied with the results.

Oh, and you only need one RewriteEngine On in the htaccess file.

Hi Doug,

I’m sure you are right. It must be just a limitation of the made with love tester.

My .htaccess file will contain the http > https and www rules from EXAMPLE 1 as well as many additional specific rules. As you suggested, I will only place “RewriteEngine On” at the beginning of the file and test live with 302s before converting to 301s.

The file would look like this:

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteRule ^OldPage$ https://mysite.com/NewPage? [R=301,L]
RewriteRule ^OldPage$ https://mysite.com/NewPage? [R=301,L]
RewriteRule ^OldPage$ https://mysite.com/NewPage? [R=301,L]
RewriteRule ^OldPage$ https://mysite.com/NewPage? [R=301,L]
etc.

Three quick questions:

Is it correct to put the http > https and www rules first in the sequence as shown?

Do I need to include “https://mysite.com” in the rules as shown?

Is it important for there to be no extra line spacing between rules as shown?

Thanks again so much for all of your valuable help!

Gerald

Htaccess directives are processed top down. So if you put the http to https and removing the www at the top then they will be processed and returned first.

Since that’s the most common change I tend to put those near the top.

There’s three basic ways to do redirects within Apache’s htaccess file.
The most complicated and most flexible is the rewrite condition/rewrite rule set like being used by the http to https set. That single set also removes the WWW.

Redirect Directive

The easiest way to do a redirect is the simple redirect statement.

Redirect 302 "/old-path" "/new-path"

That works great if the old-path is simple and should work for most redirects.

RedirectMatch Directive

The second way to perform a redirect is to use the redrectMatch. This allows you to do much more complicated redirects by using regex(regular expressions to match the URL and variable insertion.

RedirectMatch 301 "(.*)\.pdf$" "$1.html"

The above example will create a 301 redirect for all PDF documents to an HTML document with the same path and filename on the host

This would be the second most used type of redirect. You will need to have an understanding of regular expressions (regex).

mod_rewrite -RewriteCond/RewriteRule

This is the 3rd way to do redrects. It’s the most flexible but most complicated way. You’ll need a vary good understanding of regex as well as some understanding of Apache.

You can have multiple RewriteCond‘s with and/or logic for each RewriteRule.

sequence Of redirects

The sequence doesn’t matter much other than to remember that it’s top down so if you do something that changes the URL near the top, the change will be done prior to the next directives.

As for blank lines I don’t use them. However you can add comments to the htaccess file by starting them with a #

# this is a comment
#
Redirect 302 "/old-path" "/new-path"

If you want to give some real examples of what URL’s you’re looking to redirect I’d be happy to give you some live examples. It’s difficult when you are talking in hypothetical names.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.