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.

    • MozCon

      Save on Early Bird tickets and join us in London or New York City

    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

                        • shawnbeaird

                          301 Redirect for multiple links

                          I just relaunched my website and changed a permalink structure for several pages where only a subdirectory name changed. What 301 Redirect code do I use to redirect the following? I have dozens of these where I need to change just the directory name from "urban-living" to "urban", and want it to catch the following all in one redirect command. Here is an example of the structure that needs to change. Old 
                          domain.com/urban-living (single page w/ content)
                          domain.com/urban-living/tempe (single page w/ content)
                          domain.com/urban-living/tempe/the-vale (single page w/ content) New 
                          domain.com/urban 
                          domain.com/urban/tempe 
                          domain.com/urban/tempe/the-vale

                          Technical SEO | Jan 7, 2017, 3:01 PM | shawnbeaird
                          0
                        • Silviu

                          301 redirect relative or absolute path?

                          Hello everyone, Recently we've changed the URL structure on our website, and of course we had to 301 redirect the old urls to the coresponding new ones. The way the technical guys did this is: "http://www.domain.com/old-url.html" 301 redirect to "/new-url.html"
                          meaning as a relative redirect path, not an absolute one like this:
                          "http://www.domain.com/old-url.html" 301 redirect to "http://www.domain.com/new-url.html" This happened for few thousands urls, and the fact is the organic traffic dropped for those pages after this change. (no other changes were made on these pages and the new urls are as seo friendly as possible, A grade on On-Page Grader). The question is: does the relative redirect negatively affects seo, or it counts the same as an absolute path redirect? Thanks,
                          S.

                          Technical SEO | Oct 24, 2013, 7:01 AM | Silviu
                          0
                        • CsmBill

                          How do I add "noindex" or "nofollow" to a link in Wordpress

                          It's been a while since I've SEOed a Wordpress site. How do I add "nofollow" or "noindex" to specific links? I highlight the anchor text in the text editor, I click the "link" button. I could have sworn that there used to be an option in the dialogue box that pops up.

                          Technical SEO | Apr 23, 2013, 12:26 PM | CsmBill
                          0
                        • dballari

                          Where does Wordpress store the 301 redirects?

                          Hi, I've just created a campaign for my new wordpress blog and found 11 301 redirects which I was not aware of. It looks like wordpress has created them automatically. Does any one know how wordpress handles this issues or where are they stored so I can delete them? They are of no use for me. 9 of these redirects point to the same url with an added '/' and are in pages 1 is on a post. I've been changing the permalink and some urls several times and maybe one of these times the Wordpress has automatically created the 301 redirect. But why? I do not want to keep the old url. the last redirect is very strange it goes from http://www.mydomain.com/folder to http://www.mydomain.com where folder is the folder where I installed wordpress. But again, I want no one to type the url with the folder name or even know this folder exists. Any comment on this would be greatly appreciated. Thanks a lot, David

                          Technical SEO | Apr 11, 2012, 8:30 AM | dballari
                          0
                        • indigoclothing

                          Is it worth setting up 301 redirects from old products to new products?

                          This year we are using a new supplier and they have provided us a product database of approx. 5k products. About 80% of these products were in our existing database but once we have installed the new database all the URLs will have changed. There is no quick way to match the old products with the new products so we would have to manually match all 5k products if we were were to setup 301 rules for the old products pointing to the new products. Of course this would take a lot of time. So the options are: 1. Is it worth putting in this effort to make the 301 rules? 2. Or are we okay just to delete the old product pages, let the SE see the 404 and just wait for it to index the new pages? 3. Or, as a compromise, should we 301 the old product page to the new category page as this is a lot quicker for us do do than redirecting to the new product page?

                          Technical SEO | Apr 9, 2012, 2:59 PM | indigoclothing
                          0
                        • Evo

                          Loss of search engine positions after 301 redirect - what went wrong?!?

                          Hi Guys After adhering to the On Page optimisation suggestions given by SEOmoz, we redirected some of old urls to new ones.  We set 301 redirects from the old pages to new on a page by page basis but our search engine ranking subsequently fell off the radar and lost PR. We confirmed redirection with fiddler and it shows 301 permanent redirect on every page as expected. To manage redirection using a common code logic we executed following: In Http module, using “rewrite path” we route “all old page requests” to a page called “redirect.aspx? oldpagename =[oldpagename]”.  This happens at server side. In redirect.aspx we are redirecting from old page to new page using 301 permanent redirect. In the browser, when old page is requested, it will 301 redirect to new page. In hope we and others can learn from our mistakes - what did we do wrong ?!? Thanks in advance. Dave - www.paysubsonline.com

                          Technical SEO | Jan 16, 2012, 8:27 AM | Evo
                          0
                        • BaseKit

                          How to safely reduce the number of 301 redirects / should we be adding so many?

                          Hi All, We lost a lot of good rankings over the weekend with no obvious cause. Our top keyword went from p3 to p12, for example. Site speed is pretty bad (slower than 92% of sites!) but it has always been pretty bad. I'm on to the dev team to try and crunch this (beyond image optimisation) but I know that something I can effect is the number of 301 redirects we have in place. We have hundreds of 301s because we've been, perhaps incorrectly, adding one every time we find a new crawl error in GWT and it isn't because of a broken link on our site or on an external site where we can't track down the webmaster to fix the link. Is this bad practice, and should we just ignore 404s caused by external broken URLs? If we wanted to reduce these numbers, should we think about removing ones that are only in place due to external broken URLs? Any other tips for safely reducing the number of 301s? Thanks, all! Chris

                          Technical SEO | Oct 5, 2011, 11:14 AM | BaseKit
                          0
                        • Scott-Thomas

                          What is best practice for redirecting "secondary" domain names?

                          For sites with multiple top-level domains that have been secured for a business or organization, I'm curious as to what is considered best practice for setting up 301 redirects for secondary domains. Is it best to do the 301 redirects at the registrar level, or the hosting level? So that .net, .biz, or other secondary domains funnel visitors to the correct primary/main domain name. I'm looking for the "best practice" answer and want to avoid duplicate content problems, or penalties from the search engines. I'm not trying to game the system with dozens of domain names, simply the handful of domains that are important to the client. I've seen some registrars recommend hosting secondary domains, and doing redirects from the hosting level (and they use meta refresh for "domain forwarding," which I want to avoid). It seems rather wasteful to set up hosting for a secondary domain and then 301 each URL.

                          Technical SEO | Jul 13, 2011, 5:13 PM | Scott-Thomas
                          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.