• 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
        5803
        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

                              • GhillC

                                Trailing slash URLs and canonical links

                                Hi, I've seen a fair amount of topics speaking about the difference between domain names ending with or without trailing slashes, the impact on crawlers and how it behaves with canonical links.
                                However, it sticks to domain names only.
                                What about subfolders and pages then? How does it behaves with those? Say I've a site structured like this:
                                https://www.domain.com
                                https://www.domain.com/page1 And for each of my pages, I've an automatic canonical link ending with a slash.
                                Eg. rel="canonical" href="https://www.domain.com/page1/" /> for the above page. SEM Rush flags this as a canonical error. But is it exactly?
                                Are all my canonical links wrong because of that slash? And as subsidiary question, both domain.com/page1 and domain.com/page1/ are accessible. Is it this a mistake or it doesn't make any difference (I've read that those are considered different pages)? Thanks!
                                G

                                Technical SEO | | GhillC
                                0
                              • Pack

                                Redirect non slash to slash

                                Hello SEO gurus We have an issue here ( www.xyz.com.au) is having 200 responses www.xyz.com.au and www.xyz.com.au/ ( when i ran the crawl test i found this ) We have been advised to do a 301 from non slash to slash ( as our other pages are showing up with slash ) for the consistency we decided to go with this but our devs just couldnt do it. Error is - redirect loop and this site is a wordpress one Can anyone help us with this issue? Help is much appreciated.

                                Technical SEO | | Pack
                                0
                              • timfrick

                                Tool to Generate All the URLs on a Domain

                                Hi all, I've been using xml-sitemaps.com for a while to generate a list of all the URLs that exist on a domain. However, this tool only works for websites with under 500 URLs on a domain. The paid tool doesn't offer what we are looking for either. I'm hoping someone can help with a recommendation. We're looking for a tool that can: Crawl, and list, all the indexed URLs on a domain, including .pdf and .doc files (ideally in a .xls or .txt file) Crawl multiple domains with unlimited URLs (we have 5 websites with 500+ URLs on them) Seems pretty simple, but we haven't been able to find something that isn't tailored toward management of a single domain or that can crawl a huge volume of content.

                                Technical SEO | | timfrick
                                0
                              • SeaDrive

                                Redirect root domain to www

                                I've been having issues with my keyword rankings with MOZ and this is what David at M0Z asked me to do below.   Does anyone have a solution to this?  I'm not 100% sure what to do.  Does it hurt ranking to have a domain at the root or not?  Can I 301 redirect a whole site or do I have to do individual pages. "Your campaign is looking for rankings for the www version of the campaign but the URL resolves as a root domain. This would explain the discrepancy. Since there is no re-direct between the two, you can have brickmarkers.com 301 re-direct to www.site.com  which will prevent you from re-creating your campaign to track the root domain. Once the re-direct is in place it will take a while for Google to show the www version in the results in which your campaign rankings will be accurate." Thanks

                                Technical SEO | | SeaDrive
                                0
                              • KeylimeSocial

                                Domains

                                My questions is what to do with old domains we own from a past business. Is it advantages to direct them to the new domain/company or is that going to cause a problem for the new company. They are not in the same industry.

                                Technical SEO | | KeylimeSocial
                                0
                              • pauledwards

                                Beating a keyword Domain

                                Has anyone here managed to beat a keyword/exact match domain to top spot? I am currently second and wondering if it is worth the time and effort to knock it off the top spot. How hard is it to get these very annoyingly favoured domains off 1st? Any help and advice much appreciated.

                                Technical SEO | | pauledwards
                                0
                              • bThere

                                Subdomain and Domain Rankings

                                I have read here that domain names with keywords might add a boost to your search rank For instance using a completely inane example monkey-fights.com might get a boost compared to mfl.com (monkey fighting league)  when searching for "monkey fights" There seems to be a hot debate as to how much bonus the first domain might get over the second, but leaving that aside for the moment. Question 1. Would monkey-fights.mfl.com get the same kind of bonus as a root domain bonus? Question 2. If the answer to 1 above was yes would a 301 redirect from the suddomain URL to root domain URL retain that bonus I was just thinking on how hard it is to get root domains these days that are not either being squatted on etc. and if this might be a way to get the same bonus, or maybe subdomains are less bonus prone and so it would be a waste of time Thanks

                                Technical SEO | | bThere
                                0
                              • dcmike

                                Hyphenated Domain Names - "Spammy" or Not?

                                Some say hyphenated domain names are "spammy". I have also noticed that Moz's On Page Keyword Tool does NOT recognize keywords in a non-hyphenated domain name. So one would assume neither do the bots. I noticed obviously misleading words like car in carnival or spa in space or spatula, etc embedded in domain names and pondered the effect. I took it a step further with non-hyphenated domain names. I experimented by selecting totally random three or four letter blocks - Example: randomfactgenerator.net - rand omf act gene rator Each one of those clips returns copious results AND the On-Page Report Card does not credit the domain name as containing "random facts" as keywords**,** whereas www.business-sales-sarasota.com does get credit for "business sales sarasota" in the URL. This seems an obvious situation - unhyphenated domains can scramble the keywords and confuse the bots, as they search all possible combinations. YES -  I know the content should carry it but - I do not believe domain names are irrelevant, as many say. I don't believe that hyphenated domain names are not more efficient than non hyphenated ones - as long as you don't overdo it. I have also seen where a weak site in an easy market  will quickly top the list because the hyphenated domain name matches the search term - I have done it (in my pre Seo Moz days) with ft-myers-auto-air.com. I built the site in a couple of days and in a couple weeks it was on page one. Any thoughts on this?

                                Technical SEO | | dcmike
                                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.