The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

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

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. 301 Redirect "wildcard" question

    301 Redirect "wildcard" question

    Technical SEO Issues
    11 5 22.4k
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • craigycraig
      craigycraig last edited by

      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
      • HiveDigitalInc
        HiveDigitalInc last edited by

        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
        • perfectweb
          perfectweb last edited by

          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 Reply Quote 1
          • HiveDigitalInc
            HiveDigitalInc @perfectweb last edited by

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

            1 Reply Last reply Reply Quote 0
            • craigycraig
              craigycraig last edited by

              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 Reply Quote 0
              • HiveDigitalInc
                HiveDigitalInc @craigycraig last edited by

                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 Reply Quote 0
                • craigycraig
                  craigycraig @HiveDigitalInc last edited by

                  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 @HiveDigitalInc last edited by

                    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

                      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
                      • SEOKeith
                        SEOKeith last edited by

                        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
                        • iJeep
                          iJeep last edited by

                          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
                          • 1 / 1
                          • First post
                            Last post
                          • 301 redirect file question
                            tretanto
                            tretanto
                            0
                            7
                            106

                          • 301 Redirect Timing Questions
                            PatrickDelehanty
                            PatrickDelehanty
                            0
                            2
                            140

                          • 301 redirect homepage question
                            max.favilli
                            max.favilli
                            0
                            3
                            84

                          • 301 redirect question
                            TheeDigital
                            TheeDigital
                            0
                            5
                            128

                          • 301 redirect Question
                            Bryan_Loconto
                            Bryan_Loconto
                            0
                            3
                            89

                          • Questions about the Sandbox and 301 Redirects
                            Chris.Menke
                            Chris.Menke
                            0
                            2
                            316

                          • Another 301 redirect question - penalty?
                            Prime85
                            Prime85
                            0
                            6
                            406

                          • 301 Redirect Domain or 301 Redirect Domain + Interior Pages
                            Room214
                            Room214
                            0
                            7
                            1.1k

                          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
                          • Digital Marketers
                          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 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                          • Accessibility
                          • Terms of Use
                          • Privacy