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. Htaccess code to 301 redirect a folder change

    Htaccess code to 301 redirect a folder change

    Technical SEO Issues
    4 2 160
    • 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.
    • Paul_MC
      Paul_MC last edited by

      Hi,

      I need some help to redirect all my site as there was a folder change.

      eg, the old structure was www.mysite.com/stuff-1/bags.html and I need it to go to the same structure without the "-1" eg: /stuff/bags.html
      The "bags.html" will be lots of different products, so this would be a wildcard?

      What would the htaccess code need to be?

      Thanks

      1 Reply Last reply Reply Quote 0
      • Matt-Williamson
        Matt-Williamson last edited by

        Try the following in your .htaccess:

        RedirectMatch 301 ^/stuff-1/(.*)$ http://www.mysite.com/stuff/$1

        Paul_MC 2 Replies Last reply Reply Quote 1
        • Paul_MC
          Paul_MC @Matt-Williamson last edited by

          Thanks Matt,
          Worked perfectly.

          Cheers,
          Paul

          1 Reply Last reply Reply Quote 0
          • Paul_MC
            Paul_MC @Matt-Williamson last edited by

            Hi Matt,
            Maybe you can help me with this one too, as it may be similar??

            I have a series of folders that are in the structure:
            c/123456/bags.html   (the "123456" can be any series of 6 digit numbers), and the "bags.html" can be any product
            I need that to be 301 redirected to:
            /default/bags/bags.html

            Thanks,
            Paul

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            • Where to put 301 redirects in my Wordpress htaccess file?
              Benspain
              Benspain
              0
              3
              34

            • Proper 301 redirect code for http to https
              TimHolmes
              TimHolmes
              0
              2
              23.4k

            • Redirect 302 status code to 301 status code
              rijwielcashencarry040
              rijwielcashencarry040
              0
              5
              145

            • 301 redirects without .htaccess
              NancyVPS
              NancyVPS
              0
              5
              2.0k

            • Should I change a 301 redirect?
              seqal
              seqal
              0
              3
              409

            • 301 Redirects Change?
              lhc67
              lhc67
              0
              5
              692

            • 301 Redirect for homepage with language code
              kwoolf
              kwoolf
              0
              4
              2.0k

            • 301 redirect .htaccess problem
              sferrino
              sferrino
              0
              4
              709

            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