Regular Expression / Wildcard Redirect Situation
-
I am dealing with an interesting situation. Here's what's going on:
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.html
Current 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.htmlI want to make sure all variations of the above URL redirect to the new url. What wildcard 301 redirect / regular expression can I use to tackle these ?
-
Hi Nakul,
Forgive me if this is too simplistic...
The following rewrite rules should cover the examples you provided:
RedirectMatch 301 red-widgets-cid-1234.html http://www.domain.com/red-widgets-cid-4567.html
RedirectMatch 301 red-widgets-cid-1234- http://www.domain.com/red-widgets-cid-4567.html
RedirectMatch 301 red-widgets-cid-1234+ http://www.domain.com/red-widgets-cid-6789.htmlWe just need to escape the special characters (period, hyphen and plus sign).
This should cover the examples you provided, and no need for any elaborate RegEx patterns. Of course, if there are variants your example doesn't mention, things could get more complicated. (I'm also assuming here you're on an Apache environment.)
If I've misunderstood your question or the situation is more complicated than your example demonstrates, let me know.
Thanks,
Mike
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
-
Multistore 302 Redirects
I noticed that every link on my site is being flagged up as a 302 temp redirect in Moz. The reason is because we have a multi store and use GeoIP to redirect anyone coming from their respective country. I'm guessing a 302 is the wrong way to do this - can anyone shed advice on the best practice for redirecting customers to geo-specific stores?
Intermediate & Advanced SEO | | moon-boots0 -
Two Domains, Same Products/Content
We're an e-commerce company with two domains. One is our original company name/domain, one is a newer top-level domain. The older domain doesn't receive as much traffic but is still searched and used by long-time customers who are loyal to that brand, who we don't want to alienate. The sites are both identical in products and content, which creates a duplicate content issue. I have come across two options so far: 1. a 301 redirect from the old domain to the new one. 2. Optimize the content on the newer domain (the strongest of the two) and leave the older domain content as is. Does anyone know of a solution better than the two I listed above or have experience resolving a similar problem in the past?
Intermediate & Advanced SEO | | ilewis0 -
What if a 301 redirect is removed?
Suppose the following scenarios after a 301 redirects from source URL to targent URL is removed. 1. If source URL raises a 404 error, will target URL retained the link juice previously passed from source URL? 2. If source URL starts to show different content than what is showing on target URL, will the previously passed link juice be credited back to the source URL?
Intermediate & Advanced SEO | | Bull1350 -
How do you find all of your 301 redirects?
I would like a full list of 301 redirects that we have on our site. Is there a way to export it? I tried Bing Webmaster tools and the list was incomplete. We use IIS. Any ideas?
Intermediate & Advanced SEO | | EcommerceSite0 -
Canonical / 301 Redundancy
Suppose I have two dynamic URLs that lead to the identical page: www.example.com/product.php?x=1&y=1 and www.example.com/product.php?y=1 The x=1 parameter had some historical meaning, but is now unused. All references to the x=1 parameter have been removed from internal links and sitemaps. I have implemented two solutions: First, the header of www.example.com/product.php?x=1&y=1 includes: Second, the .htaccess file includes the following: Redirect permanent /product.php?x=1&y=1 http://www.example.com/product.php?y=1 Questions: 1. I assume that since canonical is still relatively new, it's best to play it safe and implement both solutions. Is this correct? 2. When I point my browser to www.example.com/product.php?x=1&y=1, it does NOT redirect to www.example.com/product.php?y=1. The address bar continues to show the non-canonical URL. Is this because the canonical tag somehow takes precedence over the 301 redirect? 3. How long will Google Webmaster Tools continue to show these as duplicates, even though I've implemeted BOTH canonical and 301? It's been a few weeks and I thought it would have rolled off by now. Thanks!
Intermediate & Advanced SEO | | ahirai0 -
Trailing Slash: Lost in Redirection?
Question here, but first the lead in. As you all know, 301 redirects don't pass on 100% of link juice. I've set up my site using htaccess to redirect all non-ww to www and redirect all URLs to have a trailing slash. FYI, the preferred domain is selected in WMT and canonical URLs appear in the head section of all pages. So now what happens when sites that link to mine don't include either the www or the trailing slash, which is actually quite common? Of course, asking the site own to correct the link is ideal, but that's not always possible. So if thousands of links on external sites are linking to http://www.site.com instead of http://www.site.com/, won't lots of link juice get lost in redirection? I can't think of anything more I can do to the URLs to reduce duplicate content and juice dilution. Thoughts? Kevin
Intermediate & Advanced SEO | | kwoolf0 -
Subdomains and SEO - Should we redirect to subfolder?
A new client has mainsite.com and a large numer of city specific sub domains i.e. albany.mainsite.com. I think that these subdomains would actually work better as subfolders i.e mainsite.com/albany rather than albany.mainsite.com. The majority of links on the subdomains link to the main site anyway i.e. mainsite.com/contactus rather than albany.mainsite.com/contactus. Having mostly main domain links on a subdomain doesnt seem like clever link architecture to me and maybe even spammy. Im not overly familiar with redirecting subdomains to subfolders. If we go the route of 301'ing subdomains to subfolders any advice/warnings?
Intermediate & Advanced SEO | | AndyMacLean0 -
We are changing ?page= dynamic url's to /page/ static urls. Will this hurt the progress we have made with the pages using dynamic addresses?
Question about changing url from dynamic to static to improve SEO but concern about hurting progress made so far.
Intermediate & Advanced SEO | | h3counsel0