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. Question about 301 redirect for trailing / ?

    Question about 301 redirect for trailing / ?

    Intermediate & Advanced SEO
    4 2 524
    • 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.
    • PEnterprises
      PEnterprises last edited by

      I am cleaning up a fairly large site.

      Some pages have a trailing slash on the end some don't. Some of the existing backlinks built used a trailing slash in the url and some didn't.

      We aren't concerned with picking a particular one but just want to get one set and stick to it from now on.

      I am wondering, would I clean this up within the same redirect in the htaccess file that takes care of the www and non www?

      example

      RewriteEngine On
      RewriteBase /
      RewriteCond %{HTTP_HOST} ^www.domain.com/ [NC]
      RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]

      I currently use that to redirect the www. to the non www as you can see. However here is what I was confused about.

      Would this code be enough to redirect ALL pages with a / to the ones without?

      or would I also need to add another code (so there is 2) to my htaccess like below?

      RewriteEngine On
      RewriteBase /
      RewriteCond %{HTTP_HOST} ^domain.com/ [NC]
      RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]

      RewriteEngine On
      RewriteBase /
      RewriteCond %{HTTP_HOST} ^www.domain.com/ [NC]
      RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]

      That way, now, even the non www pages with a trailing slash will redirect to the non www without the trailing slash.

      Hopefully you understand what I am getting at. I just want to redirect EVERYTHING to the non www WITHOUT a /

      Thank you

      Jake

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

        The one with the 2 code snippets is the one you needl! You just have to realize: what is accessed more often: the www version of a page or the / version of your pages? This speeds up apache a bit if the one that is accessed most is on top of the other.

        Cheers!

        PEnterprises 1 Reply Last reply Reply Quote 2
        • PEnterprises
          PEnterprises @YannickVeys last edited by

          Thanks Yannick,

          Quick question, I have dropped both snippets into the htaccess file. When I view my url in internet explorer it still has the trailing slash. All instances of the www. have been removed however. Is this just something IE does leaving the trailing slash even if it is in fact being redirected?

          Is there a tool or a way to check to make sure the action has been completed correctly?

          Thanks again for the help, this technical stuff is NOT my background.

          YannickVeys 1 Reply Last reply Reply Quote 0
          • YannickVeys
            YannickVeys @PEnterprises last edited by

            Hmm 🙂 Well, I'm not that technical either, I just know a little bit about 301's 😉

            Try this in stead of the second code snippet:

            RewriteCond %{HTTP_HOST} !^\.domain\.com$ [NC] RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post
            • Redirect wordpress from /%post_id%/%postname%/ to /blog/%postname%/
              Taiger
              Taiger
              0
              3
              446

            • How to 301 Redirect /page.php to /page, after a RewriteRule has already made /page.php accessible by /page (Getting errors)
              DirkC
              DirkC
              0
              2
              435

            • To redirect or not to redirect, that is the question
              CommT
              CommT
              0
              5
              126

            • How to use a 301 Redirect when the first 301 Redirect is not the same as what's indexed?
              PatriotOutfitters81
              PatriotOutfitters81
              0
              3
              66

            • 301 Redirect To Another 301 Redirect
              cbielich
              cbielich
              0
              5
              247

            • 301 redirect with /? in URL
              Aleyda
              Aleyda
              0
              5
              736

            • How to 301 redirect all URLs with /? in?
              JohnPeters
              JohnPeters
              0
              9
              331

            • Problem w/ 301 Redirect
              EricaMcGillivray
              EricaMcGillivray
              0
              5
              706

            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