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 of a subdirectory

    301 redirect of a subdirectory

    Technical SEO Issues
    6 2 135
    • 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.
    • nyc-seo
      nyc-seo last edited by

      Hello!

      I am working on a website with the following structure: example.com/sub1/sub2/sub3. The page "example.com/sub1" does not exist (I know this is not the optimal architecture to have this be a nonexistent page). But someone might type that address, so I would like it to redirect it to example.com/sub1/sub2/sub3.

      I tried the following redirect: redirect 301 /sub1 http://example.com/sub1/sub2/sub3.

      But with this redirect in place, if I go to example.com/sub1, I get redirected to example.com/sub1/sub2/sub3/sub2/sub3 (the redirect just inserts extra subdirectories).

      If someone types "example.com/sub1" into a browser, I would "example.com/sub1/sub2/sub3" to come up. Is this possible?

      Thank you!

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

        This should do the trick

        Options +FollowSymLinks
        RewriteEngine on
        RewriteBase /
        RewriteRule ^sub1 http://example.com/sub1/sub2/sub3 [R=301,NC,L]

        1 Reply Last reply Reply Quote 1
        • nyc-seo
          nyc-seo last edited by

          Matt,

          Thank you very much.

          I tried that code, but it seems to conflict with other redirects already in place. I will see what I can figure out.

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

            Hi - what other redirects do you have in place - could you stick them on here and perhaps I can help you make sure they don't conflict?

            nyc-seo 2 Replies Last reply Reply Quote 0
            • nyc-seo
              nyc-seo @Matt-Williamson last edited by

              Matt,

              Thank you so much for your generous offer! I apologize for my delayed reply. I have had to turn my focus toward other issues and let this one go for the moment.

              i really appreciate your support!

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

                Matt,

                Our web designer just made a change within Expression Engine, our CMS, and it worked!

                Here's the code:

                {if segment_2 == "" && segment_3 == ""}{redirect="sub1/sub2/sub3"}{/if}He put the code at the very top of the main /sub1/ template. It means "if segments 2 and 3 are empty, forward to /sub1/sub2/sub3."Thanks again for your help!

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • 301 Redirect
                  KaneJamison
                  KaneJamison
                  0
                  8
                  408

                • 301 redirect
                  Mark.RedGiant
                  Mark.RedGiant
                  0
                  3
                  322

                • 301 redirects
                  vibelingo
                  vibelingo
                  0
                  5
                  255

                • To 301 redirect or not to 301 redirect? duplicate content problem www.domain.com and www.domain.com/en/
                  Chris-CA
                  Chris-CA
                  0
                  5
                  456

                • Google Webmaster redirect vs 301 redirect
                  lavellester
                  lavellester
                  0
                  2
                  493

                • 301 redirect
                  AlanMosley
                  AlanMosley
                  1
                  27
                  1.9k

                • 301 Redirects
                  KT684
                  KT684
                  0
                  5
                  711

                • 301 redirect
                  Jeepster
                  Jeepster
                  0
                  18
                  2.7k

                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