Mobile app version of vmapp.org
Login or Join
Welton855

: Canonical Tags and, 301 and Legacy/Old format URLs indexed I have posted another question too which is related, but separate. Removing old format URLS This question is slightly confusing because

@Welton855

Posted in: #301Redirect #CanonicalUrl #GoogleIndex

I have posted another question too which is related, but separate.

Removing old format URLS

This question is slightly confusing because I changed the domain. Previously, we were running the site at hartnollguitars.co.uk, this has been changed to onlineguitarsales.co.uk (all 301s etc in place and I have used the Change Domain tool in Webmaster tools to activate a change of domain request, which is still in progress)

I notice Google still has indexed URLs such as:

www.example.com/products.aspx?id=1930 https://www.example.com/product/?id=1930


The above URLs, are firstly, obviously pointing to the old domain. The 301s and Domain Change Request should overcome that problem, but they both point to the same product and incorrectly to an old version of a URL.

There is a 301 redirect in place to redirect anything to products.aspx?** to /product/** but it isn't redirecting to the proper canonical URL which, in this case would be www.example.com/product/soundlab-pedal-power-450-power-bank-6-way-p1930 as per the rel="canonical" tag present in the <head> of the page returned by both of the above links.

Should there be a 301 redirect to the canonical link on all pages with any kind of old format URL, or will the rel="canonical" and domain change request be enough to tell Google to drop the indexing of the old ones and start indexing the specified canonical URLs instead?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Welton855

1 Comments

Sorted by latest first Latest Oldest Best

 

@Deb1703797

Should there be a 301 redirect to the canonical link on all pages with any kind of old format URL, or will the rel="canonical" and domain change request be enough to tell Google to drop the indexing of the old ones and start indexing the specified canonical URLs instead?


Google treats rel="canonical" as hints that a page is substantially duplicate to another page. What I recommend is a 301 redirect so that when google does it's next round of crawling your website, it will completely understand what you are trying to do.

As far as your links being incorrect, It seems like you are trying to convert product ID numbers to a product name found in a database and redirecting users to that. In apache, that cannot be done by itself.

What you should do is create a script that takes the id value as the input and looks up the correct data in the database then once its found, produce a redirect to the correct page.

Make it so that this script executes when anyone accesses a URL like whatever.com/products.aspx?id=whatever

Here's code in PHP to help you get started. I'll explain each line.

<?php
$wantedid=$_GET['id'];
$wantedname=lookupid($wantedid);
header('HTTP/1.1 301 Redirect',true);
header('Location: example.com/product/'.urlencode($wantedname),true); ?>


1st line grabs the id value which in your case is a number.

2nd line calls a lookupid function which passes in the number. This function is your own function that looks up the value in a database based on the number.

3rd line overrides the HTTP headers so that the status is now 301 instead of 200.

4th line adds a location header and specifies the new URL. In most browsers this setup is sufficient since auto-redirection happens behind the scenes. You may need to add extra HTML at the end of the PHP code to support browsers without auto-redirection support.

Because this isn't really a forum for programming questions, I won't go into great detail on how to retrieve database values and such, but you got the basics of how to redirect from a number to a value.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme