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.

      What is your Brand Authority?
      Moz

      What is your Brand Authority?

      Check yours now
    • 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
    24721
    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

      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

        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
        • 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
          • 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
            • 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

                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

                  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 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 @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
                      • 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 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
                          • 1 / 1
                          • First post
                            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

                          • Tintanus

                            Max Number of 301 Redirections?

                            Hi, We currently made a re-design of a website and we changed all our urls to make them shorter. I made more than 300 permanent redirections but plenty more are needed since WMT is showing some more 404s from old urls that I hadn't seen because they were dynamic. The question is, please, is there a limit? I think we have more than 600 already. We don't want to create a php commando to redirect all the old ones to our home, we are redirecting them to their correspondent url. By the way, Im doing them with the 301 method in .htaccess. Thanks in advance.

                            Technical SEO | | Tintanus
                            0
                          • Liggins

                            Updating inbound links vs. 301 redirecting the page they link to

                            Hi everyone, I'm preparing myself for a website redesign and finding conflicting information about inbound links and 301 redirects. If I have a URL (we'll say website.com/website) that is linked to by outside sources, should I get those outside sources to update their links when I change the URL to website.com/webpage? Or is it just as effective from a link juice perspective to simply 301 redirect the old page to the new page? Are there any other implications to this choice that I may want to consider? Thanks!

                            Technical SEO | | Liggins
                            0
                          • Houdoe

                            CNAME vs 301 redirect

                            Hi all, Recently I created a website for a new client and my next job is trying to get them higher in Google. I added them in OSE and noticed some strange backlinks. To my surprise the client has about 20 domain names. All automatically poiting to (showing) the same new mainsite now. www.maindomain.nl www.maindomain.be
                            www.maindomain.eu
                            www.maindomain.com
                            www.otherdomain.nl
                            www.otherdomain.com
                            ... Some of these domains have backlinks too (but not so much). I suggested to 301 redirect them all to the main site. Just to avoid duplicate content. But now the webhoster comes into play: "It's a problem, client has only 1 hosting account, blablabla...". They told me they could CNAME the 20 domains to the main domain. Or A-record them to an IP address. This is too technical stuff for me. So my concrete questions are: Is it smart to do anything at all or am I just harming my client? The main site is ranking pretty well now. And some backlinks are from their copy sites (probably because everywhere the logo links to the full mainsite url). Does the CNAME or A-record solution has the same effect as a 301 redirect, from SEO perspective? Many thanks,
                            Hans

                            Technical SEO | | Houdoe
                            0
                          • ulefos

                            Remove html file extension and 301 redirects

                            Hi Recently I ask for some work done on my website from a company,  but I am not sure what they've done is right.
                            What I wanted was html file extensions to be removed like
                            /ash-logs.html to /ash-logs
                            also the index.html to www.timports.co.uk
                            I have done a crawl diagnostics and have duplicate page content and 32 page title duplicates. This is so doing my head in please help This is what is in the .htaccess file <ifmodule pagespeed_module="">ModPagespeed on
                            ModPagespeedEnableFilters extend_cache,combine_css, collapse_whitespace,move_css_to_head, remove_comments</ifmodule> <ifmodule mod_headers.c="">Header set Connection keep-alive</ifmodule> <ifmodule mod_rewrite.c="">Options +FollowSymLinks -MultiViews</ifmodule> DirectoryIndex index.html RewriteEngine On 
                             # Rewrite valid requests on .html files  RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA] 
                             # Return 404 on direct requests against .html files RewriteCond %{REQUEST_URI} .html$  
                            RewriteCond %{QUERY_STRING} !rw=1 [NC]
                             RewriteRule ^ - [R=404] AddCharset UTF-8 .html # <filesmatch “.(js|css|html|htm|php|xml|swf|flv|ashx)$”="">#SetOutputFilter DEFLATE #</filesmatch> <ifmodule mod_expires.c="">ExpiresActive On
                            ExpiresByType image/gif "access plus 1 years"
                            ExpiresByType image/jpeg "access plus 1 years"
                            ExpiresByType image/png "access plus 1 years"
                            ExpiresByType image/x-icon "access plus 1 years"
                            ExpiresByType image/jpg "access plus 1 years"
                            ExpiresByType text/css "access 1 years"
                            ExpiresByType text/x-javascript "access 1 years"
                            ExpiresByType application/javascript "access 1 years"
                            ExpiresByType image/x-icon "access 1 years"</ifmodule> <files 403.shtml="">order allow,deny allow from all</files> redirect 301 /PRODUCTS http://www.timports.co.uk/kiln-dried-logs
                            redirect 301 /kindling_firewood.html http://www.timports.co.uk/kindling-firewood.html
                            redirect 301 /about_us.html http://www.timports.co.uk/about-us.html
                            redirect 301 /log_delivery.html http://www.timports.co.uk/log-delivery.html redirect 301 /oak_boards_delivery.html http://www.timports.co.uk/oak-boards-delivery.html
                            redirect 301 /un_edged_oak_boards.html http://www.timports.co.uk/un-edged-oak-boards.html
                            redirect 301 /wholesale_logs.html http://www.timports.co.uk/wholesale-logs.html redirect 301 /privacy_policy.html http://www.timports.co.uk/privacy-policy.html redirect 301 /payment_failed.html http://www.timports.co.uk/payment-failed.html redirect 301 /payment_info.html http://www.timports.co.uk/payment-info.html

                            Technical SEO | | ulefos
                            1
                          • IM_Learner

                            301 Redirect on a PDF, DOCX files?

                            Hi, I have to rename many pdf and docx files. How can I implement 301 redirect on them as they are linked from 'n' number of places? Regards, Shailendra Sial

                            Technical SEO | | IM_Learner
                            1
                          • 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 | | dballari
                            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 | | CommercePundit
                            0
                          • Kotkov

                            302 or 301 redirect to https ?

                            I am redirecting whole site to https. Is there a difference between 302 or 301 redirect for seo? Site never been indexed. Planning to do that with .htaccess command RewriteCond %{HTTPS} !=on
                            RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] There are plenty of ways http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html Which way would be the best? Thanks is advance

                            Technical SEO | | Kotkov
                            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
                          • 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

                          Access all your tools in one place. Whether you're tracking progress or analyzing data, everything you need is at your fingertips.

                          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.