undefined
Skip to content
Moz logo Menu open Menu close
  • Products
    • Moz Pro
    • Moz Pro Home
    • Moz Local
    • Moz Local Home
    • STAT
    • Moz API
    • Moz API Home
    • Compare SEO Products
    • Moz Data
  • Free SEO Tools
    • Domain Analysis
    • Keyword Explorer
    • Link Explorer
    • Competitive Research
    • MozBar
    • More Free SEO Tools
  • Learn SEO
    • Beginner's Guide to SEO
    • SEO Learning Center
    • Moz Academy
    • SEO Q&A
    • Webinars, Whitepapers, & Guides
  • Blog
  • Why Moz
    • Agency Solutions
    • Enterprise Solutions
    • Small Business Solutions
    • Case Studies
    • The Moz Story
    • New Releases
  • Log in
  • Log out
  • Products
    • Moz Pro

      Your all-in-one suite of SEO essentials.

    • Moz Local

      Raise your local SEO visibility with complete local SEO management.

    • STAT

      SERP tracking and analytics for enterprise SEO experts.

    • Moz API

      Power your SEO with our index of over 44 trillion links.

    • Compare SEO Products

      See which Moz SEO solution best meets your business needs.

    • Moz Data

      Power your SEO strategy & AI models with custom data solutions.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Free SEO Tools
    • Domain Analysis

      Get top competitive SEO metrics like DA, top pages and more.

    • Keyword Explorer

      Find traffic-driving keywords with our 1.25 billion+ keyword index.

    • Link Explorer

      Explore over 40 trillion links for powerful backlink data.

    • Competitive Research

      Uncover valuable insights on your organic search competitors.

    • MozBar

      See top SEO metrics for free as you browse the web.

    • More Free SEO Tools

      Explore all the free SEO tools Moz has to offer.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Learn SEO
    • Beginner's Guide to SEO

      The #1 most popular introduction to SEO, trusted by millions.

    • SEO Learning Center

      Broaden your knowledge with SEO resources for all skill levels.

    • On-Demand Webinars

      Learn modern SEO best practices from industry experts.

    • How-To Guides

      Step-by-step guides to search success from the authority on SEO.

    • Moz Academy

      Upskill and get certified with on-demand courses & certifications.

    • SEO Q&A

      Insights & discussions from an SEO community of 500,000+.

    Unlock flexible pricing & new endpoints
    Moz API

    Unlock flexible pricing & new endpoints

    Find your plan
  • Blog
  • Why Moz
    • Small Business Solutions

      Uncover insights to make smarter marketing decisions in less time.

    • Agency Solutions

      Earn & keep valuable clients with unparalleled data & insights.

    • Enterprise Solutions

      Gain a competitive edge in the ever-changing world of search.

    • The Moz Story

      Moz was the first & remains the most trusted SEO company.

    • Case Studies

      Explore how Moz drives ROI with a proven track record of success.

    • New Releases

      Get the scoop on the latest and greatest from Moz.

    Surface actionable competitive intel
    New Feature

    Surface actionable competitive intel

    Learn More
  • Log in
    • Moz Pro
    • Moz Local
    • Moz Local Dashboard
    • Moz API
    • Moz API Dashboard
    • Moz Academy
  • Avatar
    • Moz Home
    • Notifications
    • Account & Billing
    • Manage Users
    • Community Profile
    • My Q&A
    • My Videos
    • Log Out

The Moz Q&A Forum

  • Forum
  • Questions
  • Users
  • Ask the Community

Welcome to the Q&A Forum

Browse the forum for helpful insights and fresh discussions about all things SEO.

  1. Home
  2. SEO Tactics
  3. Technical SEO
  4. 301 Redirect "wildcard" question

Moz Q&A is closed.

After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

301 Redirect "wildcard" question

Technical SEO
5
11
24.7k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as question
Log in to reply
This topic has been deleted. Only users with question management privileges can see it.
  • craigycraig
    craigycraig last edited by Mar 11, 2011, 12:40 PM

    I have been looking at the SEOmoz redirect guide for some advice but I can't seem to find the answer : http://www.seomoz.org/learn-seo/redirection

    I have lots of URLs from a previous version of a site that look like the following:

    sitename.com/-c-25.html?sort=2d&page=1

    sitename.com/-c-25.html?sort=3a&page=1

    etc etc.

    I want to write a redirect so whenever a URL with the terms "-c-25.html" is requested it redirects to a specified page, regardless of what comes after the question mark.

    These URLs were created by our previous ecommerce software. The 'c' is for category, and each page of the cateogry created a different URL. I want to do these so I can rediect all of these URLs to the appropraite new cateogry page in a single redirect.

    Thanks for any help.

    1 Reply Last reply Reply Quote 0
    • iJeep
      iJeep last edited by Dec 23, 2012, 6:28 PM Dec 23, 2012, 6:28 PM

      When I did a similar transition with hundreds of thousands of links. I created a database table with source and destination columns. Then a script that handles all 404 requests. If the requested link matches an entry in the source column, the user is sent a 301 to the matching destination entry. That allowed for easier maintenance than a huge htaccess file and the server load caused by te script should go down over time as 301 are saved and you contact site owners to update links. The other benefit is that you can do enhanced tracking to see what is request, found and not found and where those people came from.

      1 Reply Last reply Reply Quote 0
      • topic:timeago_earlier,9 months
      • SEOKeith
        SEOKeith last edited by Mar 20, 2012, 8:49 PM Mar 20, 2012, 8:49 PM

        An easy way is to use RedirectMatch, example:

        RedirectMatch 301 /-c-25.html http://www.domain.com/new-category

        Drop the above in a .htaccess file, test it works how you expect first 🙂

        1 Reply Last reply Reply Quote 0
        • topic:timeago_earlier,about a year
        • craigycraig
          craigycraig @HiveDigitalInc last edited by Mar 18, 2011, 1:16 PM Mar 18, 2011, 1:16 PM

          OK, If I make it the first redirect then the redirection works - regardless of what is written after the 'c-21.html'.

          However the redirect is retaining the erroneous URL data after redirection. It is adding the '?blahblahblah" to the end of the new URL. I want it to dispose of this so all the redirects are routed to just one URL. How do I instruct it to not include this unwanted data in the new URL?

          Thanks

          1 Reply Last reply Reply Quote 0
          • HiveDigitalInc
            HiveDigitalInc @HiveDigitalInc last edited by Mar 11, 2011, 6:06 PM Mar 11, 2011, 6:06 PM

            Order matters in Rewrites. You will have to place that Rewrite Rule above the others.

            1 Reply Last reply Reply Quote 0
            • craigycraig
              craigycraig @HiveDigitalInc last edited by Mar 11, 2011, 1:57 PM Mar 11, 2011, 1:41 PM

              I thought that may do it but still nothing. Maybe I am entering it wrong? Here is the code in .htaccess:

              RewriteEngine On

              RewriteBase /test/

              RewriteRule ^index.php$ - [L

              ]RewriteCond %{REQUEST_FILENAME} !-f

              RewriteCond %{REQUEST_FILENAME} !-d

              RewriteRule . /test/index.php [L]

              RewriteRule ^-c-21.html(.*)$ http://www.mysitename.com/test/category/t-shirts/dolphin_tshirts [R=301,L

              ]

              The redirect just doesn't happen.

              EDIT: If I write a standard redirect : Redirect 301 /test/-c-21.html then it will redirect to the desired page but it will retain the ?blahblah and add it to the new URL. I want it to work like this but discard the ?blahblahblah after redirecting.

              1 Reply Last reply Reply Quote 0
              • HiveDigitalInc
                HiveDigitalInc @craigycraig last edited by Mar 11, 2011, 1:31 PM Mar 11, 2011, 1:31 PM

                If you need these to be 301 redirects...

                RewriteRule ^-c-25.html(.*)$ http://www.yoursite.com/dolphin_tshirts [R=301,L]

                craigycraig HiveDigitalInc 3 Replies Last reply Mar 18, 2011, 1:16 PM Reply Quote 0
                • craigycraig
                  craigycraig last edited by Mar 11, 2011, 1:28 PM Mar 11, 2011, 1:23 PM

                  Just to calrify I need a URL that has

                  /-c-25.html?blahblahblah

                  to change to:

                  /dolphin_tshirts

                  Regardless of that is written in the blahblahblah part.

                  HiveDigitalInc 1 Reply Last reply Mar 11, 2011, 1:31 PM Reply Quote 0
                  • HiveDigitalInc
                    HiveDigitalInc @perfectweb last edited by Mar 11, 2011, 12:58 PM Mar 11, 2011, 12:58 PM

                    I think that would probably work for him, assuming that the category IDs remain the same.

                    1 Reply Last reply Reply Quote 0
                    • perfectweb
                      perfectweb last edited by Mar 11, 2011, 12:52 PM Mar 11, 2011, 12:52 PM

                      Would something liek this work:

                      RewriteRule ^-c-(.).html(.)$ category/$1.html$2 [R,NC]

                      I've not tested it, nor do I claim to be an expert, but I think it will work for what you're tryign to acheive - e.g. -c-25.html becomes category/25.html

                      HiveDigitalInc 1 Reply Last reply Mar 11, 2011, 12:58 PM Reply Quote 1
                      • HiveDigitalInc
                        HiveDigitalInc last edited by Mar 11, 2011, 12:47 PM Mar 11, 2011, 12:47 PM

                        If your site is in PHP, you could simply add the code...

                        $targetURL = "http://www.sitename.com/whatever-page-you-what";

                        if(stristr($_SERVER['REQUEST_URI'],"-c-25.html")) {

                        header("HTTP/1.1 301 Moved Permanently"); header("Location: $targetURL");

                        }

                        ?>

                        If you don't have access to PHP, you could add a line like this to your HTACCESS file...

                        RewriteCond %{THE_REQUEST} (c-25.html) [NC]
                        RewriteRule .* http://www.sitename.com/your-target-page [L,R=301]

                        Someone might want to double check me on that rewriteRule above, though.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        1 out of 11
                        • First post
                          1/11
                          Last post

                        Got a burning SEO question?

                        Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


                        Start my free trial


                        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.

                        • See all categories

                        Related Questions

                        • aliho

                          What is the difference between 301 redirects and backlinks?

                          i have seen some 301 redirects on my site  billsonline, can anyone please explain the difference between backlinks and 301 redirects,  i have read some articles where the writer was stating  that  301 are not good for website.

                          Technical SEO | May 9, 2024, 5:14 PM | aliho
                          0
                        • TaraLP

                          Delete old blog posts after 301 redirects to new pages?

                          Hi Moz Community, I've recently created several new pages on my site using much of the same copy from blog posts on the same topics (we did this for design flexibility and a few other reasons). The blogs and pages aren't exactly identical, as the new pages have much more content, but I don't think there's a point to having both and I don't want to have duplicate content, so we've used 301 redirects from the old blog posts to the new pages of the same topic. My question is: can I go ahead and delete the old blog posts? (Or would there be any reasons I shouldn't delete them?) I'm guessing with the 301 redirects, all will be well in the world and I can just delete the old posts, but I wanted to triple check to make sure. Thanks so much for your feedback, I really appreciate it!

                          Technical SEO | Oct 4, 2019, 2:20 PM | TaraLP
                          1
                        • Gotmoxie

                          How do I fix a 301 Redirect Loop?

                          Saturday I waas doing some correcting of some duplicate titles, including nofollowing tags, etc. (my main problem was duplicate titles due to tags and categories being indexed). Now this morning I see that one of my pages refuses to load, citing a 301 redirect loop. http://www.incredibleinfant.com/feeding/switching-baby-formula/ Originally, the page was posted under the wrong category. http://www.incredibleinfant.com/uncategorized/switching-baby-formula I resaved it under the correct category (feeding) and now it won't load. Can someone help me figure out how to correct this mess? Thanks so much Heather

                          Technical SEO | Dec 12, 2012, 1:25 PM | Gotmoxie
                          0
                        • bimmer540

                          A script to automatically write 301 redirect rules to htaccess?

                          I was wondering if anyone could help provide some resources on how to automatically write 301 redirect rules to htaccess.  Allow me to explain... I'm building a new website and the primary users are businesses.  They have their own profile pages on the site. The URL is based off of their Company Name. In the event that they decided to change their name... reasons being, perhaps they mispelled it the first time, or they're removing LLC or adding Inc, I want to also change the URL and redirect the old URL to the new URL. Since the URL is based off of their Company Name, making a change to the company name would make a change to the URL.  I know it doesn't have to work this way, but for our purpose this works best. In case the old URL had any links to it, I wanted to see if there was an way to automatically update an htaccess file with a 301 redirect from the old URL to the new one. Could anyone point me in the right direction of how to do this?  Perhaps a sample script.  I've done a lot of searches on Google and can't seem to find anything. e.g. Original:
                          Name:  XYZ Widgets
                          URL:  website.com/xyz-widgets New - business changes their company name in their profile:
                          Name:  XYZ Widgets, Inc.
                          URL:  website.com/xyz-widgets-inc Upon the user saving the changes in their profile, I'd like to write a 301 redirect to an htaccess file:
                          Redirect 301 /xyz-widgets http://www.website.com/xyz-widgets-inc I know how to manually write redirects and I've got a pretty smart web developer.  We've just never triggered a script to automatically write to an htaccess file before. Is this possible?  Any resources are appreciated.  Any security risks? Thanks!

                          Technical SEO | Jul 18, 2012, 12:53 AM | bimmer540
                          0
                        • koamit

                          What should be use 301 or 302 redirection for 404 pages

                          Please suggest which redirection we should use for 404 pages- 301 or 302. If you can elaborate it with reason then it will be highly appreciated.

                          Technical SEO | May 15, 2012, 10:26 AM | koamit
                          0
                        • CommercePundit

                          Does it really matter to maintain 301 redirect after de-indexing of old URLs?

                          Today, I was reading latest blog post on SEOmoz blog about. Uncrawled 301s - A Quick Fix for When Relaunches Go Too Well This is very interesting study about 301 & How it useful to maintain traffic. I'm working on eCommerce website and I have done similar stuff on my website. I have big confusion to manage 301 redirect. My website generates new URLs due to following actions. Re-write dynamic URLs. Re-launch entire website on different eCommerce platform. [osCommerce to Magento Commerce] Re-name category. Trasfer one product from one category to another category. I'm managing my 301 redirect with old practice. Excel sheet data from Google webmaster tools and set specific new URLs for redirect. Hoooo... Now, I have 8.5K redirect in htaccess... And, I'm thinking it's too much. Can we remove old 301 redirect from htaccess or not? This is big question for me. Because, all pages are not hyperlink on external website. Google have just de-indexed old URLs and indexed new URLs. So, Is it require to maintain 301 redirect after Google process?

                          Technical SEO | Jun 15, 2012, 11:59 AM | CommercePundit
                          0
                        • Adrian_Kingwell

                          What tools produce a complete list of all URLs for 301 redirects?

                          I am project managing the rebuild of a major corporate website and need to set up 301 redirects from the old pages to the new ones. The problem is that the old site sits on multiple CMS platforms so there is no way I can get a list of pages from the old CMS. Is there a good tool out there that will crawl through all the sites and produce a nice spreadsheet with all the URLs on it? Somebody mentioned Xenu but I have never used it. Any recommendations? Thanks -Adrian

                          Technical SEO | Feb 24, 2012, 8:34 AM | Adrian_Kingwell
                          0
                        • pbrothers24

                          How many jumps between 301 redirects is acceptable?

                          For example, I have a page A that should be redirected to page D, but instead A redirects to B, B redirects to C and C redirects to D. It's something I came across and wondering if its worth the dev time to change it. Thanks!

                          Technical SEO | Oct 10, 2011, 3:50 PM | pbrothers24
                          0

                        Get started with Moz Pro!

                        Unlock the power of advanced SEO tools and data-driven insights.

                        Start my free trial
                        Products
                        • Moz Pro
                        • Moz Local
                        • Moz API
                        • Moz Data
                        • STAT
                        • Product Updates
                        Moz Solutions
                        • SMB Solutions
                        • Agency Solutions
                        • Enterprise Solutions
                        Free SEO Tools
                        • Domain Authority Checker
                        • Link Explorer
                        • Keyword Explorer
                        • Competitive Research
                        • Brand Authority Checker
                        • Local Citation Checker
                        • MozBar Extension
                        • MozCast
                        Resources
                        • Blog
                        • SEO Learning Center
                        • Help Hub
                        • Beginner's Guide to SEO
                        • How-to Guides
                        • Moz Academy
                        • API Docs
                        About Moz
                        • About
                        • Team
                        • Careers
                        • Contact
                        Why Moz
                        • Case Studies
                        • Testimonials
                        Get Involved
                        • Become an Affiliate
                        • MozCon
                        • Webinars
                        • Practical Marketer Series
                        • MozPod
                        Connect with us

                        Contact the Help team

                        Join our newsletter
                        Moz logo
                        © 2021 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                        • Accessibility
                        • Terms of Use
                        • Privacy

                        Looks like your connection to Moz was lost, please wait while we try to reconnect.