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
-
HTTPS & Redirects
Hi We're moving to https imminently & I wondered if anyone has advice on redirects. Obviously we'll be redirecting all http versions to https - but should I be checking how many redirects are in each chain and amending accordingly? If there's 4-5 in a chain, remove the middle unnecessary URLS ? Advice please 🙂
Intermediate & Advanced SEO | | BeckyKey0 -
I've got duplicate pages. For example, blog/page/2 is the same as author/admin/page/2\. Is this something I should just ignore, or should I create the author/admin/page2 and then 301 redirect?
I'm going through the crawl report and it says I've got duplicate pages. For example, blog/page/2 is the same as author/admin/page/2/ Now, the author/admin/page/2 I can't even find in WordPress, but it is the same thing as blog/page/2 nonetheless. Is this something I should just ignore, or should I create the author/admin/page2 and then 301 redirect it to blog/page/2?
Intermediate & Advanced SEO | | shift-inc0 -
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 -
Citation/Business Directory Question...
A company I work for has two numbers... one for the std call centre and one for tracking SEO. Now, if local citation/business directory listings have the same address but different numbers, will this affect local/other SEO results? Any help is greatly appreciated! 🙂
Intermediate & Advanced SEO | | geniusenergyltd0 -
Is there any importance in including http:// in the url?
I have seen some sites that always redirect to https and some sites that always redirect to http://, but lately I have seen sites that force the url to just the site. As in [sitename].com, no www. no http://. Does this affect SEO in anyway? Is it good or bad for other things? I was surprised when I saw it and don't really know what effect it has.
Intermediate & Advanced SEO | | MarloSchneider0 -
E-Commerce site - How do I geo-target towns/cities/states if there aren't any store locations?
Site = e-commerce Products = clothing (no apparel can be location specific like sports gear where you can do the location specific team gear (NBA, NFL, etc)) Problems = a. no store front b. I don't want to do any sitewides (footers, sidebars, etc) because of the penguin update Question = How do you geo-target these category pages and product pages? Ideas = a. reviews with clients locations b. blog posts with clients images wearing apparel and location description and keywords that also links back to that category or be it product page (images geo- targeted, tags, and description) c. ? Thanks in advance!
Intermediate & Advanced SEO | | Cyclone0 -
How many pages to 301 Redirect
Hi Mozzers, My site has 11,200 pages indexed in Google and I'm looking to remove some of the lesser content which should probably have been picked up by Panda. However these pages work out to about 1,100 in total and I'm not sure whether to remove these bit by bit or just do it in one fell swoop? Does Google not like a site's indexed pages fluctuating too quickly? Are there any other considerations I should be aware of? Thanks!
Intermediate & Advanced SEO | | panini0 -
How to Redirect
What is the htaccess code to redirect everything in a directory to a file? Thanks!
Intermediate & Advanced SEO | | tylerfraser0