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
-
301 redirecting to anchor points
A client has just given me a list of redirect URLs as requested of them. However, they're wanting to redirect a bunch of pages to various anchor points within the same page. For example: /pages/about might redirect to: /pages/our-story#our-mission And: /pages/history might redirect to: /pages/our-story#history Is there any problem with this? I've never seen or been asked to redirect like this before.
Intermediate & Advanced SEO | | muzzmoz0 -
Multilingual Redirection
Hey there awesome Mozzers, I have a site that it automatically redirects people by using geolocation ( i know that probably is not good ) to the various languages of the site. I just wanted to know Is 301 or 302 the best option? ( I've heard that for language re-directions 302 is the best case scenario ) My main page for example is www.example.com and it automatically redirects with a 301 to www.example.com/en for any language that is not there. What is the best case scenario? Leave it to redirect to /en or just leave it go to the root page www.example.com.
Intermediate & Advanced SEO | | Angelos_Savvaidis0 -
On Page Content. has a H2 Tag but should I also use H3 tags for the sub headings within this body of content
Hi Mozzers, My on page content comes under my H2 tag. I have a few subheadings within my content to help break it up etc and currently this is just underlined (not bold or anything) and I am wondering from an SEO perspective, should I be making these sub headings H3 tags. Otherwise , I just have 500-750 words of content under an H2 tag which is what I am currently doing on my landing pages. thanks pete
Intermediate & Advanced SEO | | PeteC120 -
Cross Domain Rel Canonical tags vs. Rel Canonical Tags for internal webpages
Today I noticed that one of my colleagues was pointing rel canonical tags to a third party domain on a few specific pages on a client's website. This was a standard rel canonical tag that was written Up to this point I haven't seen too many webmasters point a rel canonical to a third party domain. However after doing some reading in the Google Webmaster Tools blog I realized that cross domain rel canonicals are indeed a viable strategy to avoid duplicate content. My question is this; should rel canonical tags be written the same way when dealing with internal duplicate content vs. external duplicate content? Would a rel=author tag be more appropriate when addressing 3rd party website duplicate content issues? Any feedback would be appreciated.
Intermediate & Advanced SEO | | VanguardCommunications0 -
Php 301 redirect
Hi I am migrating an old wordpress site to a custom PHP site and the URL profiles will be different, so want to retain all link profiles and more importantly if a user visits the old urls via search then they are seamlessly transferred to the new equivalent page For example www.domain.com/about-us is going to need to redirect to www.domain.com/aboutus.php www.domain.com/furniture is going to need to redirect to www.domain.com/furniture-collections.php etc What is the best way of achieving this apart from .htaccess as not 100% confident of doing this. Could it be done via PHP or using meta tags?
Intermediate & Advanced SEO | | ocelot0 -
301 redirect recommendations
One of our clients we are working on have two sites the main with a PR5 and a separate one with a PR4. We are planning on doing a 301 from the PR4 to a page on the PR5 Is it best to do: www.PR4.com ----> www.PR5.com/releveantPR4page or www.PR4.com/page ----> www.PR5.com/releveantPR4page Most pages on the PR4 site can fit into one PR5 page logically. However the PR4 has an about us, contact us, blog/with posts, FAQ, Applications, Legal Resources which are all pretty out dated.. The PR4 site is kinda messy and we are not sure if it will be easy to 301 each page individually with the user in mind. can we do a sitewide 301 redirect from the root PR4.com to a page PR/5.com/releveantPR4page and also do deeper 301's? PR4.com/PR4page ---> PR5.com/releveantPR4page
Intermediate & Advanced SEO | | Bryan_Loconto0 -
How canonical url harm our website???
Even though my website has no similar/copied content, i used rel=canonical for all my website pages. Is Google or yahoo make any harm to my SERP's?? EX: http://www.seomoz.org is my site, in that i used canonical as rel="<a class="attribute-value">canonical</a>" href="http://www.seomoz.org" to my home page like that similar to all pages, i created rel=canonical. Is search engine harm my website???
Intermediate & Advanced SEO | | MadhukarSV0 -
Not allowing me 301 Redirect
I am trying redirect my old site to my new site, both on the same domain. For one reason or another, I am having a hard time redirecting the some of the old urls to the new site. Please let me know how I can fix this issue. Below are the following old urls that are not allowing me to redirect: <colgroup><col width="636"></colgroup>
Intermediate & Advanced SEO | | Melia
| http://www.meliacaribetropical.com/press/melia-caribe-tropical-announces-fall-promotion.html |
| http://www.meliacaribetropical.com/press/melia-international-brand-overhaul.html |
| http://www.meliacaribetropical.com/spanish/accommodations/ |
| http://www.meliacaribetropical.com/spanish/dining/ |
| http://www.meliacaribetropical.com/spanish/entertainment/ |
| http://www.meliacaribetropical.com/spanish/events/ |
| http://www.meliacaribetropical.com/spanish/flintstones/ |
| http://www.meliacaribetropical.com/spanish/gallery/ |
| http://www.meliacaribetropical.com/spanish/gallery/beach.html |
| http://www.meliacaribetropical.com/spanish/gallery/dining.html |
| http://www.meliacaribetropical.com/spanish/gallery/pools.html |
| http://www.meliacaribetropical.com/spanish/press/ |
| http://www.meliacaribetropical.com/spanish/press/melia-caribe-tropical-announces-fall-promotion.html |
| http://www.meliacaribetropical.com/spanish/press/melia-international-brand-overhaul.html |0