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. Intermediate & Advanced SEO
    4. How to do a 301 redirect for url's with this structure?

    How to do a 301 redirect for url's with this structure?

    Intermediate & Advanced SEO
    2 2 287
    • 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.
    • mr_w
      mr_w last edited by

      In an effort to clean up my url's I'm trying to shorten them by using a 301 redirect in my .htaccess file. How would I set up a rule to grab all urls with a specific structure to a new shorter url examples:

      http://www.yakangler.com/articles/reviews/other-reviews/item/article-title

      http://www.yakangler.com/reviews/article-title

      So in the example above dynamically redirect all url's with /articles/reviews/other-reviews/item/ in it to /reviews/ so

      http://www.yakangler.com/articles/reviews/boat-reviews/item/1550-review-nucanoe-frontier

      http://www.yakangler.com/articles/reviews/other-reviews/item/1551-review-spyderco-salt

      http://www.yakangler.com/articles/reviews/fishing-gear-reviews/item/1524-slayer-inc-sinister-swim-tail

      would be...

      http://www.yakangler.com/reviews/1550-review-nucanoe-frontier

      http://www.yakangler.com/reviews/1551-review-spyderco-salt

      http://www.yakangler.com/reviews/1524-slayer-inc-sinister-swim-tail

      with one 301 redirect rule in my .htaccess file.

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

        You can do this via RedirectMatch statements. There is an example of different match types you could use here. Basically, you create a pattern and then the code is smart enough to redirect based on that pattern.

        http://www.askapache.com/htaccess/301-redirect-with-mod_rewrite-or-redirectmatch.html#301_Redirects_RedirectMatch

        Your redirect might look something like this though you might want to adjust the pattern match the directory in between /reviews/ and /item/. Mine is just a basic alphanumeric catch all.

        RedirectMatch 301 ^/articles/reviews/([-A-z0-9]+)/item/(.*)$ http://clients.qwconsulting.com/reviews/$1

        I hope that helps.

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        • Migrating From Parameter-Driven URL's to 'SEO Friendly URL's (Slugs)
          PatrickDelehanty
          PatrickDelehanty
          0
          2
          292

        • What's the best URL structure?
          MoosaHemani
          MoosaHemani
          0
          4
          281

        • What to do when all products are one of a kind WYSIWYG and url's are continuously changing. Lots of 404's
          evolvingSEO
          evolvingSEO
          0
          6
          201

        • Doubts with URL's structure
          crackingmedia
          crackingmedia
          0
          4
          125

        • Remove URLs that 301 Redirect from Google's Index
          CommT
          CommT
          0
          3
          8.9k

        • URL Structure Change - 301 Redirect - on large website
          Kurt_Steinbrueck
          Kurt_Steinbrueck
          0
          3
          2.1k

        • Can some brilliant mozzer out there teach a moron/newbie like me how to 301 redirect several URL's I have?
          AlanMosley
          AlanMosley
          0
          7
          487

        • Don't want to lose page rank, what's the best way to restructure a url other than a 301 redirect?
          marig
          marig
          0
          6
          1.0k

        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