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. White Hat / Black Hat SEO
    4. How to remove trailing slashes in URLs using .htaccess (Apache)?

    How to remove trailing slashes in URLs using .htaccess (Apache)?

    White Hat / Black Hat SEO
    5 2 25.1k
    • 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.
    • esiow2013
      esiow2013 last edited by

      I want my URLs to look like these:

      http://www.domain.com/buy

      http://www.domain.com/buy/shoes

      http://www.domain.com/buy/shoes/red

      Thanks in advance!

      1 Reply Last reply Reply Quote 0
      • Devanur-Rafi
        Devanur-Rafi last edited by

        Hi, here you go.....

        RewriteRule ^(.)/(?.)?$ $1$2 [R=301,L]

        Please note that the thing which looks like a capital V in the above rule is actually the backward slash and forward slash together.

        Best,

        Devanur Rafi

        esiow2013 1 Reply Last reply Reply Quote 1
        • esiow2013
          esiow2013 @Devanur-Rafi last edited by

          Thanks Devanur! Big help. By the way, I'm still looking for an opinion about this and I'm sure you can help me with this issue:http://moz.com/community/q/how-can-i-301-redirect-a-series-of-pages-ex-page-1-page-2-page-3-to-one-landing-page-new-url

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

            And what is the difference of this to the one you've answered?

            RewriteBase /
            RewriteRule ^(.*)/$ $1 [R,L]

            Devanur-Rafi 1 Reply Last reply Reply Quote 0
            • Devanur-Rafi
              Devanur-Rafi @esiow2013 last edited by

              I am sorry my friend. Somehow I missed your response.

              It should have been: RewriteRule ^(.*)/$ /$1 [R,L]

              So, you missed the /

              And it is also used to remove the trailing slash from URLs just like the one that I gave you earlier.

              Best,

              Devanur Rafi

              1 Reply Last reply Reply Quote 1
              • 1 / 1
              • First post
                Last post
              • Is that trailing slashes necessity for an SEO doing blogs
                Martijn_Scheijbeler
                Martijn_Scheijbeler
                0
                3
                31

              • How Important is it to Use Keywords in the URL
                BradsDeals
                BradsDeals
                0
                5
                152

              • Removing duplicated content using only the NOINDEX in large scale (80% of the website).
                Lukas_TheCurious
                Lukas_TheCurious
                0
                14
                477

              • 301 domain name URL variants for canonicalization question in htaccess?
                MikeTek
                MikeTek
                0
                2
                498

              • Where is the rule here to remove trailing slashes in URLs?
                Devanur-Rafi
                Devanur-Rafi
                0
                6
                161

              • Is using Zeus's gateway feature to display contents from the different URL OK to do?
                HypermediaSystems
                HypermediaSystems
                0
                3
                167

              • Why do websites use different URLS for mobile and desktop
                Sarbs
                Sarbs
                0
                3
                508

              • Advice on using the disavow tool to remove hacked website links
                blagger
                blagger
                0
                3
                1.4k

              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