• majorAlexa

        See all notifications

        Skip to content
        Moz logo Menu open Menu close
        • Products
          • Moz Pro
          • Moz Pro Home
          • Moz Local
          • Moz Local Home
          • STAT
          • Moz API
          • Moz API Home
          • Compare SEO Products
          • Moz Data
        • Free SEO Tools
          • Domain Analysis
          • Keyword Explorer
          • Link Explorer
          • Competitive Research
          • MozBar
          • More Free SEO Tools
        • Learn SEO
          • Beginner's Guide to SEO
          • SEO Learning Center
          • Moz Academy
          • MozCon
          • Webinars, Whitepapers, & Guides
        • Blog
        • Why Moz
          • Digital Marketers
          • Agency Solutions
          • Enterprise Solutions
          • Small Business Solutions
          • The Moz Story
          • New Releases
        • Log in
        • Log out
        • Products
          • Moz Pro

            Your all-in-one suite of SEO essentials.

          • Moz Local

            Raise your local SEO visibility with complete local SEO management.

          • STAT

            SERP tracking and analytics for enterprise SEO experts.

          • Moz API

            Power your SEO with our index of over 44 trillion links.

          • Compare SEO Products

            See which Moz SEO solution best meets your business needs.

          • Moz Data

            Power your SEO strategy & AI models with custom data solutions.

          Let your business shine with Listings AI
          Moz Local

          Let your business shine with Listings AI

          Learn more
        • Free SEO Tools
          • Domain Analysis

            Get top competitive SEO metrics like DA, top pages and more.

          • Keyword Explorer

            Find traffic-driving keywords with our 1.25 billion+ keyword index.

          • Link Explorer

            Explore over 40 trillion links for powerful backlink data.

          • Competitive Research

            Uncover valuable insights on your organic search competitors.

          • MozBar

            See top SEO metrics for free as you browse the web.

          • More Free SEO Tools

            Explore all the free SEO tools Moz has to offer.

          NEW Keyword Suggestions by Topic
          Moz Pro

          NEW Keyword Suggestions by Topic

          Learn more
        • Learn SEO
          • Beginner's Guide to SEO

            The #1 most popular introduction to SEO, trusted by millions.

          • SEO Learning Center

            Broaden your knowledge with SEO resources for all skill levels.

          • On-Demand Webinars

            Learn modern SEO best practices from industry experts.

          • How-To Guides

            Step-by-step guides to search success from the authority on SEO.

          • Moz Academy

            Upskill and get certified with on-demand courses & certifications.

          • MozCon

            Save on Early Bird tickets and join us in London or New York City

          Unlock flexible pricing & new endpoints
          Moz API

          Unlock flexible pricing & new endpoints

          Find your plan
        • Blog
        • Why Moz
          • Digital Marketers

            Simplify SEO tasks to save time and grow your traffic.

          • Small Business Solutions

            Uncover insights to make smarter marketing decisions in less time.

          • Agency Solutions

            Earn & keep valuable clients with unparalleled data & insights.

          • Enterprise Solutions

            Gain a competitive edge in the ever-changing world of search.

          • The Moz Story

            Moz was the first & remains the most trusted SEO company.

          • New Releases

            Get the scoop on the latest and greatest from Moz.

          Surface actionable competitive intel
          New Feature

          Surface actionable competitive intel

          Learn More
        • Log in
          • Moz Pro
          • Moz Local
          • Moz Local Dashboard
          • Moz API
          • Moz API Dashboard
          • Moz Academy
        • Avatar
          • Moz Home
          • Notifications
          • Account & Billing
          • Manage Users
          • Community Profile
          • My Q&A
          • My Videos
          • Log Out

        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. Home
        2. SEO Tactics
        3. Technical SEO
        4. How to force a trailing slash after the domain name

        Moz Q&A is closed.

        After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

        How to force a trailing slash after the domain name

        Technical SEO
        2
        11
        5800
        Loading More Posts
        • Watching

          Notify me of new replies.
          Show question in unread.

        • Not Watching

          Do not notify me of new replies.
          Show question in unread if category is not ignored.

        • Ignoring

          Do not notify me of new replies.
          Do not show question in unread.

        • Oldest to Newest
        • Newest to Oldest
        • Most Votes
        Reply
        • Reply as question
        Locked
        This topic has been deleted. Only users with question management privileges can see it.
        • JollyBoy
          JollyBoy last edited by

          My campaign analysis is predictably listing domain.com and domain.com/ as repeated content. I've searched and searched but cannot find a way to force a trailing slash on the end of the domain name unless there's a file or directory after it..

          Is there a way to accomplish this using .htaccess

          1 Reply Last reply Reply Quote 0
          • JollyBoy
            JollyBoy @JollyBoy last edited by

            I've gone with this .htaccess from your soulgorithm.com:

            Options +FollowSymlinks
            RewriteEngine on
            RewriteBase /
            RewriteCond %{HTTP_HOST} ^www.domain.co.uk [NC]
            RewriteRule (.*) http://domain.co.uk/$1 [L,R=301]

            RewriteCond %{REQUEST_URI} (.)/$
            RewriteCond %{REQUEST_FILENAME}.php -f
            RewriteRule (.
            )/$ $1.php [L]

            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_FILENAME}.php -f
            RewriteRule .* %{REQUEST_FILENAME}/ [R=301,L]

            and I'm now getting the results I'm after. I'm getting similar behaviour to you in Firefox and IE, which explains a lot. I really appreciate the length you've gone to to help me here, so big thank you!

            1 Reply Last reply Reply Quote 0
            • BailHotline
              BailHotline @JollyBoy last edited by

              Test Site: soulgorithm.com

              In the .htaccess file for this site:

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

              RewriteCond %{REQUEST_URI} (.)/$
              RewriteCond %{REQUEST_FILENAME}.html -f
              RewriteRule (.
              )/$ $1.html [L]

              RewriteCond %{REQUEST_URI} (.)/$
              RewriteCond %{REQUEST_FILENAME}.php -f
              RewriteRule (.
              )/$ $1.php [L]

              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteCond %{REQUEST_FILENAME}.html -f [OR]
              RewriteCond %{REQUEST_FILENAME}.php -f
              RewriteRule .* %{REQUEST_FILENAME}/ [R=301,L]

              Which has the following effect:

              soulgorithm.com > soulgorithm.com/

              (slash is added, but only shows in IE and looks

              likes its being stripped by Firefox but page

              still loads fine)

              soulgorithm.com/ > soulgorithm.com/
                 
                  (loads fine, but only shows in IE and looks

              likes its being stripped by Firefox but page

              still loads fine)

              soulgorithm.com/test > soulgorithm.com/test/

              (loads fine, slash even shows in FF)

              soulgorithm.com/test/ > soulgorithm.com.com/test/

              (loads fine)

              soulgorithm.com/testdir > soulgorithm.com/testdir/

              (loads fine, slash even shows in FF)

              soulgorithm.com/testdir/ > soulgorithm.com.com/testdir/

              (loads fine, slash even shows in FF)

              Let me know if this is what you see. I feel likes its getting close to working.

              1 Reply Last reply Reply Quote 2
              • JollyBoy
                JollyBoy @JollyBoy last edited by

                Thanks for sticking with this. Rather than me share the domain, do you know of any example sites using your code (or similar) which add a trailing slash after the domain name? I'd like to rule out my browser stripping it out.

                1 Reply Last reply Reply Quote 0
                • BailHotline
                  BailHotline @JollyBoy last edited by

                  Man, my mind is blown right now. I'm not giving up and hopefully someone else can chime in on this discussion and shed some light on this issue.

                  The code provided should have worked. Let me look into it some more. Also, if you don't mind what is the actual domain name?

                  1 Reply Last reply Reply Quote 0
                  • JollyBoy
                    JollyBoy @JollyBoy last edited by

                    That's right - nothing in there but the code you supplied.

                    1 Reply Last reply Reply Quote 0
                    • BailHotline
                      BailHotline @JollyBoy last edited by

                      Is this the only thing you have in your htaccess file?

                      if not, I would remove everything in the file and only have what i posted above, and let me know if it works.

                      1 Reply Last reply Reply Quote 0
                      • JollyBoy
                        JollyBoy @JollyBoy last edited by

                        Nope. Still no trailing slashes being added.

                        1 Reply Last reply Reply Quote 0
                        • BailHotline
                          BailHotline @JollyBoy last edited by

                          Try just the following:

                          Let me know if this works for you.

                          RewriteEngine On
                          RewriteBase /
                          RewriteCond %{REQUEST_FILENAME} !-f
                          RewriteCond %{REQUEST_URI} !index.php
                          RewriteCond %{REQUEST_URI} !(.*)/$
                          RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301]
                          
                          1 Reply Last reply Reply Quote 0
                          • JollyBoy
                            JollyBoy @BailHotline last edited by

                            Thanks for the reply, but this looks like all the other examples I've found. My .htaccess file looks like this :

                            DirectoryIndex index.php

                            RewriteEngine On
                            RewriteCond %{REQUEST_FILENAME} !-f
                            RewriteCond %{REQUEST_FILENAME} !-d
                            RewriteRule ^(.*)$ $1.php [L,QSA]

                            RewriteCond %{REQUEST_FILENAME} !-f
                            RewriteCond %{REQUEST_URI} !(.)/$
                            RewriteRule ^(.
                            )$ http://domain.co.uk/$1/ [L,R=301]

                            But I get the following redirects going on:

                            domain.co.uk > domain.co.uk (ie nothing happens)

                            domain.co.uk/ > domain.co.uk (ie slash is removed)

                            domain.co.uk/page2 > domain.co.uk/page2 (ie nothing happens, but page loads)

                            domain.co.uk/page2/ > Internal server error

                            Any ideas?

                            BailHotline JollyBoy 8 Replies Last reply Reply Quote 0
                            • BailHotline
                              BailHotline last edited by

                              Hi Clive.

                              Yes, you can easily do this with an .htaccess file, here is the code:

                              RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

                              Just replace "domain.com" with your proper url for your site. This should be all that is needed.

                              Hope this helps!

                              JollyBoy 1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              • First post
                                Last post

                              Browse Questions

                              Explore more categories

                              • Moz Tools

                                Chat with the community about the Moz tools.

                              • SEO Tactics

                                Discuss the SEO process with fellow marketers

                              • Community

                                Discuss industry events, jobs, and news!

                              • Digital Marketing

                                Chat about tactics outside of SEO

                              • Research & Trends

                                Dive into research and trends in the search industry.

                              • Support

                                Connect on product support and feature requests.

                              • See all categories

                              Related Questions

                              • AL123al

                                Old domain to new domain

                                Hi, A website on server A is no longer required. The owner has redirected some URLS of this website (via plugin) to his new website on server B  -but not all URLS. So when I use COMMAND site:website A , I see a mixture of redirected URLS and not redirected URLS.Therefore two websites are still being indexed in some form and causing duplication. However, weirdly when I crawl with Screaming Frog I only see one URL which is 301 redirected to the new website.  I would have thought I'd see lots of URLs which hadn't been redirected. How come it is different to using the site:command? Anyway, how do I move to the new website completely without the old one being indexed anymore. I thought I knew this but have read so many blogs I've confused myself! Should I: Redirect all URLS via the HTACESS file on old website on server A? There are lots of pages indexed so a lot of URLs. What if I miss some? or Point the old domain via DNS to server B and do the redirects in website B HTaccess file? This seems more sensible but does this method still retain the website rankings? Thanks for any help

                                Technical SEO | | AL123al
                                0
                              • usDragons

                                Spammers created bad links to old hacked domain, now redirected to our new domain. Advice?

                                My client had an old site hacked (let's call it "myolddomain.com") and the hackers created many links in other hacked sites with links such as http://myolddomain.com/styless.asp?jordan-12-taxi-kids-cheap-T8927.html The old myolddomain.com site was redirected to a different new site since then, but we still see over a thousand spam links showing up in the new site's Search Console 404 crawl errors report. Also, using the links: operator in google search, we see many results of spam links. Should we be worried about these bad links pointing to our old site and redirecting to 404s on the new site? What is the best recommendation to clean them up? Ignore? 410s? Other? I'm seeing conflicting advice out there. The old site is hosted by the client's previous web developer who doesn't want to clean anything up on their end without an ongoing hosting contract. So beyond turning redirects on or off, the client doesn't want to pay for any additional hosting. So we don't have much control over anything related to "myolddomain.com". 😞 Thanks in advance for any assistance!

                                Technical SEO | | usDragons
                                0
                              • christyrobinson

                                Help: domain name change and Google News

                                Hi. I work for a regional news source, and our (separate) Spanish-language news publication recently changed its domain name. The publication lost its Google News inclusion. Most of their traffic came from Google News, so traffic tanked. They're trying to get back in. They reapplied but didn't get approved. They're now in the 30-day waiting period to reapply again. The website is run by a third-party company, which handled the domain name change in April (2015). That company has been running their site for a couple of years. Our in-house devs' hands are tied on helping, because we (at the mother company) don't manage their site. This third party has not been responsive. The Spanish pub folks have reached out to me to help them prepare for Round 2 of reapplication. I'm the mothership in-house SEO, but I've never experienced this situation before. Because everything seems to be in order besides the ham-handed changes, my best advice to them so far is: You'll have to wait until Google gets to know you again, unfortunately. Does that sound right? Any pointers out there for bringing their best possible A-game to the next round?

                                Technical SEO | | christyrobinson
                                1
                              • inlinear

                                Correct linking to the /index of a site and subfolders: what's the best practice? link to: domain.com/ or domain.com/index.html ?

                                Dear all, starting with my .htaccess file: RewriteEngine On
                                RewriteCond %{HTTP_HOST} ^www.inlinear.com$ [NC]
                                RewriteRule ^(.*)$ http://inlinear.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^./index.html 
                                RewriteRule ^(.)index.html$ http://inlinear.com/ [R=301,L] 1. I redirect all URL-requests with www. to the non www-version...
                                2. all requests with "index.html" will be redirected to "domain.com/" My questions are: A) When linking from a page to my frontpage (home) the best practice is?: "http://domain.com/" the best and NOT: "http://domain.com/index.php" B) When linking to the index of a subfolder "http://domain.com/products/index.php" I should link also to: "http://domain.com/products/" and not put also the index.php..., right? C) When I define the canonical ULR, should I also define it just: "http://domain.com/products/" or in this case I should link to the definite file: "http://domain.com/products**/index.php**" Is A) B) the best practice? and C) ? Thanks for all replies! 🙂
                                Holger

                                Technical SEO | | inlinear
                                0
                              • MEI152

                                Shopping Carts & Sub Domains

                                I was hoping someone could guide me in making the correct decision regarding integrating my existing domain with a hosted shopping cart. I have an existing website to promote my bricks and mortar retail operation and am expanding into web retailing. I will be using one of the major hosted shopping carts. What is the best way to join the two components from an SEO perspective? Have the cart as a sub domain of my main site, or move my existing domain name to be hosted by the cart provider and have both components operate under the same general domain? I have read arguments that putting your cart within a sub domain is not a good idea because any clout of the pre-existing domain will not be shared with the  sub domain; that they will be treated as two separate sites. I have also read that using a sub domain is a good idea being that the content focus of the main domain (marketing and blogs) is different form the focus of the sub domain (product sales), and that the two components would benefit form earning their own rankings undiluted by the other. And, I have also read that search engines are getting good at being able to deduce that an eCommerce sub domain is legitimate extension of a content intensive main domain, and that they treat the two components as a combined whole. What is the truth? Which is the better way to go? Any guidance would be appreciated.

                                Technical SEO | | MEI152
                                0
                              • eventurerob

                                Trailing Slashes on Home Pages

                                I do not think I have a problem here, but a second opinion would be welcomed... I have a site which has a the rel=canonical tag with the trailing slash displayed. ie www.example.com/ The sitemap has it without the trailing slash. www.example.com Google has it's cached copy with the trailing slash but the browser displays it without. I want to say it's perfectly fine (for the home page) as I tend to think they are treated (with/without trailing slashes) as the same canonical URL.

                                Technical SEO | | eventurerob
                                0
                              • media-surfer

                                Umlaut in domain

                                Hi, My client wants to expand it's business to Germany and logically we need a domain name to match. We've found a great one and regsiterd several variants to it. However I just found out that in Germany it is possible (while here it's not) to register a domain with an umlaut. My question is: will google assign more value to: schädlinge.de than schadlinge.de when users search for schädlinge? If yes, how large will the difference be? (I will use an umlaut in the title etc) Kind regards,
                                Jason.

                                Technical SEO | | media-surfer
                                0
                              • upick-162391

                                Trailing Slashes In Url use Canonical Url or 301 Redirect?

                                I was thinking of using 301 redirects for trailing slahes to no trailing slashes for my urls. EG: www.url.com/page1/ 301 redirect to www.url.com/page1 Already got a redirect for non-www to www already. Just wondering in my case would it be best to continue using htacces for the trailing slash redirect or just go with Canonical URLs?

                                Technical SEO | | upick-162391
                                0

                              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 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                              • Accessibility
                              • Terms of Use
                              • Privacy

                              Looks like your connection to Moz was lost, please wait while we try to reconnect.