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. Duplicate content on URL trailing slash

    Duplicate content on URL trailing slash

    Intermediate & Advanced SEO
    6 4 7.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.
    • yacpro13
      yacpro13 last edited by

      Hello,

      Some time ago, we accidentally made changes to our site which modified the way urls in links are generated. At once, trailing slashes were added to many urls (only in links).

      Links that used to send to
      example.com/webpage.html

      Were now linking to
      example.com/webpage.html/

      Urls in the xml sitemap remained unchanged (no trailing slash).

      We started noticing duplicate content (because our site renders the same page with or without the trailing shash). We corrected the problematic php url function so that now, all links on the site link to a url without trailing slash.

      However, Google had time to index these pages. Is implementing 301 redirects required in this case?

      1 Reply Last reply Reply Quote 1
      • BlueprintMarketing
        BlueprintMarketing last edited by

        I have provided the Apache and Nginx configurations you would need in addition to a URL that will convert

        Apache Htaccess to Nginx

        The instructions are right here

        Remove Trailing Slash

        Just like with the WWW example, some prefer to remove the trailing slash. It's a commonly debated question that you'll find around the Internet, but it just depends on what you prefer.

        Remember, though, your browser and even your server, by default, add a trailing slash to a directory. It is done for a reason. If you must strip the trailing slash, though, this is how you would do it:

        <code class="hljs apache">RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !(.*)$
        RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]</code>
        

        For Nginx

        nginx configuration location ~ (.)$ { } location / { if (!-e $request_filename){ rewrite ^(.)$ http://www.domain.com/$1 redirect; } }

        The explanation for this rule is the same as it is for when we want to add a trailing slash, just in reverse. We can also specify specific directories that we don't want apply this rule over.

        <code class="hljs apache">RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_URI} !directory/(.*)$
        RewriteCond %{REQUEST_URI} !(.*)$
        RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]</code>
        

        For Nginx

        nginx configuration location ~ directory/(.)$ { } location ~ (.)$ { } location / { if (!-e $request_filename){ rewrite ^(.*)$ http://www.domain.com/$1 redirect; } }

        Please see the note about mod_dir and the DirectorySlash directive in the previous example. You might need to turn this directive off.

        HTaccess converter for Apache to Nginx configuration.

        http://winginx.com/en/htaccess

        https://www.maxcdn.com/one/tutorial/remove-trailing-slash/

        https://www.crucialhosting.com/knowledgebase/htaccess-apache-rewrites-examples

        https://moz.com/community/q/how-to-remove-trailing-slashes-in-urls-using-htaccess-apache

        https://gist.github.com/nathos/4645164

        1 Reply Last reply Reply Quote 3
        • GlobeRunner
          GlobeRunner last edited by

          If you have changed the URLs with trailing slashes, then there are a few things you'll want to do:

          • make sure all the internal links on your site are updated to point to the proper version.

          • make sure that the sitemap.xml file(s) are correct, pointing to the proper version.

          • set up 301 permanent redirects so that the ones with the slash are redirecting to the old URLs.

          As long as you have corrected the links internally, updated the sitemap file, and set up the 301 redirects, everything should go "back to normal" within a fairly short period of time. You will need to give it time, though, as Google will need to re-crawl all of those URLs and get it all ironed out.

          yacpro13 1 Reply Last reply Reply Quote 4
          • MattRoney
            MattRoney last edited by

            Hi yacpro13! Did Eric or Thomas answer your question, and if so, would you mind marking one or both responses as a "Good Answer?" 🙂

            Otherwise, what questions do you still have?

            1 Reply Last reply Reply Quote 1
            • yacpro13
              yacpro13 @GlobeRunner last edited by

              Hi Eric,

              I was at Step 3 of your 3 Step plan, looking for confirmation as to whether or not the 301 redirects were required in this situation.

              Thanks!

              BlueprintMarketing 1 Reply Last reply Reply Quote 0
              • BlueprintMarketing
                BlueprintMarketing @yacpro13 last edited by

                Yes you want to have it match the canonical tag so most effective method is to 301 redirect so they match the canonical tag site map and robots.txt etc.  You can use a Regex code like this at the end of the URL /?$ in the case of category URLs it will allow them when needed.

                if you use the proper 301 you will not have to deal with the category issue anyway.

                rel="canonical" href="https://moz.com/community/q/duplicate-content-on-url-trailing-slash" />

                I hope this is able to shed more light on the issue and great answer Eric.

                Hope I was of help,

                Tom

                1 Reply Last reply Reply Quote 3
                • 1 / 1
                • First post
                  Last post
                • Should I switch from trailing slash to no trailing slash?
                  ThompsonPaul
                  ThompsonPaul
                  0
                  6
                  1.6k

                • Trailing Slash and Non-Trailing Slash Inconsistency
                  nerdieb
                  nerdieb
                  0
                  3
                  412

                • Is it better to have trailing slash or no trailing slash in URLs and what if both variations work?
                  webmethod
                  webmethod
                  0
                  4
                  2.8k

                • Duplicate content within sections of a page but not full page duplicate content
                  J_Sinclair
                  J_Sinclair
                  0
                  3
                  112

                • Duplicate content across internation urls
                  jazavide
                  jazavide
                  0
                  3
                  173

                • Duplicate content throughout multiple URLs dilemma
                  TammyWood
                  TammyWood
                  0
                  2
                  910

                • Mobile Site - Same Content, Same subdomain, Different URL - Duplicate Content?
                  Carson-Ward
                  Carson-Ward
                  0
                  6
                  1.5k

                • Capitals in url creates duplicate content?
                  dimitreliasb
                  dimitreliasb
                  0
                  11
                  2.2k

                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