• 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

                              • nathangdavidson2

                                How can you promote a sub-domain ahead of a domain on the SERPs?

                                I have a new client that wants to promote their subdomain uk.imagemcs.com and have their main domain imagemcs.com fall off the SERPs. Objective? Get uk.imagemcs.com to rank first for UK 'brand' searches. Do a search for 'imagem creative services' and you should see the issue (it looks like rules have been applied to the robots.txt on the main domain to exclude any bots from crawling - but since they've been indexed previously I need to take action as it doesn't look great!). I think I can do this by applying a permanent redirect from the main domain to the subdomain at domain level and then no-indexing the site - and then resubmit the sitemap. My slight concern is that this no-indexing of the main domain may impact on the visibility of the subdomains (I'm dealing with uk.imagemcs.com, but there is us.imagemcs.com and de.imagemcs.com) and was looking for some assurance that this would not be the case. My understanding is that subdomains are completely distinct from domains and as such this action should have no impact on the subdomains. I asked the question on the Webmasters Forum but haven't really got anywhere
                                https://productforums.google.com/forum/#!msg/webmasters/1Avupy3Uw_o/hu6oLQntCAAJ Can anyone suggest a course of action? many thanks, Nathan

                                Technical SEO | | nathangdavidson2
                                0
                              • SushiUK

                                WooCommerce category naming conventions

                                I am managing a woocommerce store selling prescription glasses/spectacles. We have a lot of categories with similar names and I want to adopt the best possible naming convention to get the best from search. So we have a number of similar categories for both Men's and women's glasses. Currently they are named as follows: Women's Glasses-Women's Rimless Glasses
                                -Women's Semi Rimless Glasses
                                -Women's Plastic Glasses
                                -Women's Metal Glasses
                                -Women's Retro Glasses Currently, this results in the following URL structure for sub categories: https://www.glassesonspec.co.uk/product-category/womens-glasses-2/womens-rimless-glasses/ (For some reason WooCommerce is adding -2 to the end of the primary category name, it will not let me change it for some reason, this is the subject of a further investigation!) So first question, is there too much duplication of the word glasses on the sub items? for example, should they read; Women's Glasses
                                -Rimless
                                -Semi Rimless
                                -Plastic
                                -Metal
                                -Retro Hence giving this URL structure: https://www.glassesonspec.co.uk/product-category/womens-glasses-2/rimless/ OR, should we change the top level category name to just Women's and let the sub categories complete the picture?: Women's
                                -Rimless Glasses
                                -Semi Rimless Glasses
                                -Plastic Glasses
                                -Metal Glasses
                                -Retro Glasses Giving this example URL structure: https://www.xxxxxxxxxxxxx.co.uk/product-category/womens/rimless-glasses/ This would solve my hyphenation problem, however my fear is the top level category on it's own is not descriptive enough when viewed as stand alone: https://www.xxxxxxxxxxxxx.co.uk/product-category/womens/ The second part of my question relates to how to deal with the change in URL structure. I am using Yoast Premium, so will that pick up the changes and automatically redirect to the new one as it does when done manually? Or will I need to take a different approach using HTACCESS commands? I hope the above makes sense, Many thanks, Bob

                                Technical SEO | | SushiUK
                                0
                              • TimHolmes

                                301 redirect adding trailing slash to url

                                I am looking into a .htacess file for a site I look after and have noticed that the urls are all 301 redirecting from a none slash directory to a trailing slashed directory/folders. e.g. www.domain.com/folder gets 301 redirected to www.domain.com/folder/ Will this do much harm and reduce the effect on the page and any links pointing to the site be lessened? Secondly I am not sure what part of my htaccess is causing the redirect. RewriteCond %{HTTP_HOST} !^www.domain.co.uk [NC] RewriteCond %{HTTP_HOST} !^$
                                RewriteRule ^(.*) http://www.domain.co.uk/$1 [L,R,NE] RewriteCond %{THE_REQUEST} ^./index.php
                                RewriteRule ^(.)index.php$ /$1 [R=301,L] or could a wordpress ifmodule be causing the problem? Any info would be apreciated.

                                Technical SEO | | TimHolmes
                                0
                              • Amr-Haffar

                                Will removing the trailing slash impact my SEO?

                                Hi there, We have a company website based on Wordpress. I just noticed that under Settings > Permalinks I can configure the look of the URLs and even remove the trailing slash. We have about 2-300 pages online. If I remove the trailing slash now, will that negatively impact our SEO in anyway for existing pages? Thanks!

                                Technical SEO | | Amr-Haffar
                                0
                              • zeepartner

                                Block Domain in robots.txt

                                Hi. We had some URLs that were indexed in Google from a www1-subdomain. We have now disabled the URLs (returning a 404 - for other reasons we cannot do a redirect from www1 to www) and blocked via robots.txt. But the amount of indexed pages keeps increasing (for 2 weeks now). Unfortunately, I cannot install Webmaster Tools for this subdomain to tell Google to back off... Any ideas why this could be and whether it's normal? I can send you more domain infos by personal message if you want to have a look at it.

                                Technical SEO | | zeepartner
                                0
                              • fabrizzio

                                Localized domains and duplicate content

                                Hey guys, In my company we are launching a new website and there's an issue it's been bothering me for a while. I'm sure you guys can help me out. I already have a website, let's say ABC.com I'm preparing a localized version of that website for the uk so we'll launch ABC.co.uk Basically the websites are going to be exactly the same with the difference of the homepage. They have a slightly different proposition. Using GeoIP I will redirect the UK traffic to ABC.co.uk and the rest of the traffic will still visit .com website. May google penalize this? The site itself it will be almost the same but the homepage. This may count as duplicate content even if I'm geo-targeting different regions so they will never overlap. Thanks in advance for you advice

                                Technical SEO | | fabrizzio
                                0
                              • Grumpy_Carl

                                Domain authority and keyword difficulty

                                I know there are too many variables for a certain answer, however do people take their domain authority into account when using keyword difficulty tool? I have a new domain which only has a score of seven at the moment.  When using the keyword searching tool what is the maximum difficulty level keywords people would target initially? Obviously I would seek to increase the difficulty of the words over time but to start off its a hard choice between keywords which can be ranked for in a reasonable period of time and the keywords which are getting enough traffic to make the effort worthwhile.

                                Technical SEO | | Grumpy_Carl
                                0
                              • RobMay

                                Using hyphenated sub-domains or non-hyphenated sub-domains? What is the question! I Any takers?

                                For our corporate business level domain, we are exploring using a hyphenated sub-domain foir a project. Something like www.go-figure.extreme.com I thought from a user perspective it seems cluttered. The domain length might also be an issue with the new Algorithm big G has launched in recent past. I know with past experience, hyphenated domains usually take longer to index, as they are used by spammers more frequently and can take longer to get out of the supplementary index. Our company site has over 90 million viewers / year, so our brand is well established and traffic isn't an issue. This is for a corporate level project and I didn't have the answer! Will this work? anyone have any experience testing this. Any thoughts will help! Thanks, Rob

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