Wildcard Redirects & Canonical Tags
-
I have an interesting situation.
Current URLs Example1:
www.domain.com/red-widgets-cid-1234.html
www.domain.com/red-widgets-cid-1234-1.html
www.domain.com/red-widgets-cid-1234-1-1.htmlCanonical on All Above URLs:
www.domain.com/red-widgets-cid-1234.htmlNew URL:
www.domain.com/red-widgets-cid-4567.htmlCurrent URLs Example2:
www.domain.com/red-widgets-cid-1234+10.html
www.domain.com/red-widgets-cid-1234+10-1.html
www.domain.com/red-widgets-cid-1234+10-1-1.htmlCanonical on All Above URLs:
www.domain.com/red-widgets-cid-1234+10.htmlNew URL:
www.domain.com/red-widgets-cid-6789.htmlCurrent URLs Example3:
www.domain.com/red-widgets-cid-1234+10+5.html
www.domain.com/red-widgets-cid-1234+10+5-1.html
www.domain.com/red-widgets-cid-1234+10+5-1-1.htmlCanonical on All Above URLs:
www.domain.com/red-widgets-cid-1234+10+5.htmlNew URL:
www.domain.com/american-red-widgets-cid-6789+5.htmlI want to make sure all variations of the above URL redirect to the new URLs. However, as you see in Example 3, we are dealing with variables that are passed on. (+5 in this case).
Question 1: What wildcard 301 redirect / regular expression can I use to tackle these ?
Question 2: If we redirect www.domain.com/red-widgets-cid-1234+10+5.html to www.domain.com/red-widgets-cid-6789+5.html and www.domain.com/red-widgets-cid-6789+5.html contains the canonical tag www.domain.com/american-red-widgets-cid-6789+5.html, any concerns or red flags here ?
-
Hi Nakul
Here is my stab at question 1, my methodology is trial and error so if any guru's want to take another shot at it please do so. Here is a nice 301 reference page lots of examples
RewriteEngine On
RewriteRule ^(.)_red-widgets-cid-1234.html$ www.domain.com/red-widgets-cid-4567.html [R=301]
#Example 2
RewriteRule ^(.)_red-widgets-cid-1234+10.html$ www.domain.com/red-widgets-cid-6789.html [R=301]
#Example 3
RewriteRule ^(.*)_red-widgets-cid-1234+10+5.html$ www.domain.com/american-red-widgets-cid-6789+5.html [R=301,L]We use ^ to denote start of string
We use $ to denote end of string
We use (.*)_ to look for a keyword. In the examples above we are looking for what each page name has in common
We use [R=301,L] for the Last rewrite, previous rules just use [R=301]
One thing that (maybe) needed is escaping the +signs in the string so like example 3 would be
^(.*)_red-widgets-cid-1234+10+5.html$ www.domain.com/american-red-widgets-cid-6789+5.html
Also I may missed a wildcard on some of these....
^(.)_red-widgets-cid-1234+10+5(.).html$ www.domain.com/american-red-widgets-cid-6789+5.html
Question 2:
Canonical to self canonical tag is okay.
This = That and That = That ..........Okay
This = That and That = The ..........Not OkayHope that puts you on track
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Move to new domain using Canonical Tag
At the moment, I am moving from olddomain.com (niche site) to the newdomain.com (multi-niche site). Due to some reasons, I do not want to use 301 right now and planning to use the canonical pointing to the new domain instead. Would Google rank the new site instead of the old site? From what I have learnt, the canonical tag lets Google know that which is the main source of the contents. Thank you very much!
Intermediate & Advanced SEO | | india-morocco0 -
AMP - The what, why and how of it
Hi There, In our company, we never had AMP implemented on sites that we SEO for. We want to start doing that now. I know the basics of AMP and their requirements, however, I need to know a lot more about it from an SEO perspective of this before I actually get developers onto it. I want to know all the 1) risks involved, 2) the best ways to implement it (plugin etc.), 3) why it is worth it. I also want to know how to see if a developer knows what he is talking about - and really will do it the right way without messing me up? Are there any specific questions I should ask, or information he should be aware of? Also, is there a way for it it be done for pages that have more than just text like quote forms, sliding headers etc.? Should we only do it for the blog section of our site? I would greatly appreciate any links to additional resources on this topic, (not why to use AMP, but everything else) I greatly appreciate you taking the time to answer my question
Intermediate & Advanced SEO | | Ruchy0 -
301 redirect with DNS?
Quick question. Is it possible to 301 redirect a non-www to www. (properly in terms of SEO) with DNS (C Name, A name, or other) ..have searched around and found conflicting information. Would like to know a definite answer. I usually implement all 301 redirects with htaccess. However have a client situation where we only have access to the CMS, but which does have DNS settings. thanks in advance, Greg
Intermediate & Advanced SEO | | GregDixson0 -
Hreflang Tags & Canonicals Being Used
We have a site on which both hreflang tags and canonicals are being used. There are multiple languages, but for this I'll explain our problem using two. There are a ton of dupe page titles coming up in GSC, and we're not sure if we have an issue or not. First, the hreflang tags are implement properly. UK page pointing there, US page pointing there. Further down the page, there are canonical tags - except the UK canonical tag points to the UK page, and the US version points to the US page. I'm not sure if this will cause an issue in terms of SEO or indexing. Has anyone experienced this before or does anything have any insight into this? Thanks much! Matt
Intermediate & Advanced SEO | | Snaptech_Marketing0 -
I currently have a canonical tag pointing to a different url for single page categories on eCommerce site. Is this wrong ?
Hi Mozzers, I have a query regarding canonical tags on my eCommerce site.. Basically on my category pages whereby I have more than 1 page, I currently use next/prev rel and also have a canonical tag pointing to the View all version of that page. This is believe is correct.(see example - http://goo.gl/2gz6LV However, from looking at the view source on my other pages, I have noticed I have canonical tags on all my category pages which are only a single page and these canonicaltag are pointing to a different url. I enclose an example . Please advise Category page - http://goo.gl/Pk4zYl This is where the canonical tag points to - http://goo.gl/EwKv26 Another example Category Page - http://goo.gl/4gWTdD This is where the canonical tag for that page points to http://goo.gl/qm4HV7 Should I either make sure that categories that are only 1 page , don't have a canonical tag at all ? or do I have a canonical tag on say every page on my website for safety pointing to the main url for that page. The later, I imagine would be a belt and braces approach but I don't want to screw up anything if it's not advised? Please help/ Kind regards Pete
Intermediate & Advanced SEO | | PeteC120 -
URL Parameters as a single solution vs Canonical tags
Hi all, We are running a classifieds platform in Spain (mercadonline.es) that has a lot of duplicate content. The majority of our duplicate content consists of URL's that contain site parameters. In other words, they are the result of multiple pages within the same subcategory, that are sorted by different field names like price and type of ad. I believe if I assign the correct group of url's to each parameter in Google webmastertools then a lot these duplicate issues will be resolved. Still a few questions remain: Once I set f.ex. the 'page' parameter and i choose 'paginates' as a behaviour, will I let Googlebot decide whether to index these pages or do i set them to 'no'? Since I told Google Webmaster what type of URL's contain this parameter, it will know that these are relevant pages, yet not always completely different in content. Other url's that contain 'sortby' don't differ in content at all so i set these to 'sorting' as behaviour and set them to 'no' for google crawling. What parameter can I use to assign this to 'search' I.e. the parameter that causes the URL's to contain an internal search string. Since this search parameter changes all the time depending on the user input, how can I choose the best one. I think I need 'specifies'? Do I still need to assign canonical tags for all of these url's after this process or is setting parameters in my case an alternative solution to this problem? I can send examples of the duplicates. But most of them contain 'page', 'descending' 'sort by' etc values. Thank you for your help. Ivor
Intermediate & Advanced SEO | | ivordg0 -
Tagged URL ranking organically
I've noticed that one of our GA tagged urls are ranking organically & therefore is skewing the referral data. The campaign that we were tracking is no longer active but the link still works, but it's going to an old landing page. I asked our developers if we could redirect it but they said that it didn't work. Does anyone have some advise or a solution for this? Thanks!
Intermediate & Advanced SEO | | Elihn0 -
Best way to implement canonical tags on an ecommerce site with many filter options?
What would be the best way to add canonical tags to an ecommerce site with many filter options, for example, http://teacherexpress.scholastic.com? Should I include a canonical tag for all filter options under a category even though the pages don't have the same content? Thanks for reading!
Intermediate & Advanced SEO | | DA20130