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. Trailing slash 301 redirect code

    Trailing slash 301 redirect code

    Technical SEO Issues
    10 4 5.4k
    • 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.
    • jamesjackson
      jamesjackson last edited by

      Hi,

      I have code for redirecting trailing slash to non-trailing slash, which works fine:

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

      (got code from http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html)

      But I cant find a code for redirecting to the trailing slash version anywhere, and I cant modify the above code myself.

      Can someone help resolve this issue please, or point me to a resource.

      Thanks very much

      James

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

        I could probably be of service but since I'm Danish You'll have to give me an example of a "trailing" slash.. A guess it's a slash that tips the left? eg: "" or is it this one: "/"

        if you help me understand what you mean I might be able to help you 🙂

        seoug_2005 jamesjackson 2 Replies Last reply Reply Quote 0
        • seoug_2005
          seoug_2005 @ReneReinholdt last edited by

          If a URL has trailing slash ( / ), and a user types the URL without trailing slash, would an 404 error will be shown ?

          ReneReinholdt seoug_2005 jamesjackson 4 Replies Last reply Reply Quote 0
          • ReneReinholdt
            ReneReinholdt @seoug_2005 last edited by

            In my experience no 🙂

            1 Reply Last reply Reply Quote 1
            • seoug_2005
              seoug_2005 @seoug_2005 last edited by

              Then why it is suggested to have one version - with or without trailing slash ?

              1 Reply Last reply Reply Quote 0
              • ReneReinholdt
                ReneReinholdt @seoug_2005 last edited by

                the reson is: Back in the day (I do not know if it still does this, havent tested it or had cause to do so.) google indexed example.com/page/ and example.com/page as two different pages.

                The quick fix is to make a RegEx that "tests for the excistense of a trailing slash at the end ofg the url" and then use that in your .htaccess to redirect all urls without to an url with. In other words add a trailing slash. (makes sence I hope.)

                You could do the same thing with rel=canonical (even easier imo. since you can use php and do it in the relevant templates)

                Here is Matts word on trailing slashes: http://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260

                1 Reply Last reply Reply Quote 0
                • jamesjackson
                  jamesjackson @ReneReinholdt last edited by

                  Hi Rene,

                  Sorry for the delay in getting back to you. It's this one "/".

                  I'm not in favour of using the canonical tag as it's not a directive, so I want ideally a 301 redirect code for it

                  thanks

                  1 Reply Last reply Reply Quote 0
                  • jamesjackson
                    jamesjackson @seoug_2005 last edited by

                    no, google can (and often does) index both pages as separate URL's

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

                      I use Wordpress and Thesis and have them do all the work for me, so I'm not a hands-on expert and can't verify the accuracy of the following URLs, but it looks like they may address your questions. Let us know if one of these works for you.

                      http://enarion.net/web/htaccess/trailing-slash/

                      http://soulpass.com/2008/01/11/htaccess-add-trailing-slash-to-url/ (be sure to read whole post)

                      jamesjackson 1 Reply Last reply Reply Quote 0
                      • jamesjackson
                        jamesjackson @KeriMorgret last edited by

                        Hi Keri,

                        Thanks for the suggested solution. The enarion solution works for my regular URL's but then causes me issues with some of the more complicated javascript/ajax functionality on the site. No idea why, (bit over my head to be honest) but my developer suggested that it wasnt a good idea to it anyway (again ,for reasons I dont fully understand!)

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        • Massive jump in amount of pages being crawled - from lazyload or trailing slash redirects??
                          0
                          1
                          43

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

                        • How to redirect 302 status to 301 status code using wordpress
                          ThompsonPaul
                          ThompsonPaul
                          0
                          4
                          1.3k

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

                        • Redirect a 301 Redirect
                          RedCaffeine
                          RedCaffeine
                          0
                          5
                          98

                        • Web config redirects not working where a trailing slash is involved
                          AndrewAkesson
                          AndrewAkesson
                          0
                          5
                          6.4k

                        • 301 Redirect Domain or 301 Redirect Domain + Interior Pages
                          Room214
                          Room214
                          0
                          7
                          1.1k

                        • Trailing Slashes In Url use Canonical Url or 301 Redirect?
                          RyanKent
                          RyanKent
                          0
                          7
                          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