undefined
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.

    Track AI Overviews in Keyword Research
    Moz Pro

    Track AI Overviews in Keyword Research

    Try it free!
  • 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
  • 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
5.9k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as question
Log in to reply
This topic has been deleted. Only users with question management privileges can see it.
  • JollyBoy
    JollyBoy last edited by Mar 8, 2012, 8:14 PM

    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 Mar 10, 2012, 4:04 AM Mar 10, 2012, 4:04 AM

      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 Mar 12, 2012, 3:14 PM Mar 9, 2012, 10:37 PM

        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 Mar 9, 2012, 8:50 PM Mar 9, 2012, 8:50 PM

          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 Mar 9, 2012, 8:41 PM Mar 9, 2012, 8:41 PM

            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 Mar 9, 2012, 7:49 PM Mar 9, 2012, 7:49 PM

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

              1 Reply Last reply Reply Quote 0
              • BailHotline
                BailHotline @JollyBoy last edited by Mar 9, 2012, 7:30 PM Mar 9, 2012, 7:30 PM

                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 Mar 9, 2012, 5:48 PM Mar 9, 2012, 5:48 PM

                  Nope. Still no trailing slashes being added.

                  1 Reply Last reply Reply Quote 0
                  • BailHotline
                    BailHotline @JollyBoy last edited by Mar 9, 2012, 2:31 AM Mar 9, 2012, 2:31 AM

                    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 Mar 9, 2012, 12:43 AM Mar 9, 2012, 12:43 AM

                      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 Mar 10, 2012, 4:04 AM Reply Quote 0
                      • BailHotline
                        BailHotline last edited by Mar 8, 2012, 8:49 PM Mar 8, 2012, 8:49 PM

                        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 Mar 9, 2012, 12:43 AM Reply Quote 0
                        • 1 / 1
                        1 out of 11
                        • First post
                          1/11
                          Last post

                        Got a burning SEO question?

                        Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


                        Start my free trial


                        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

                        • Shrine.SEO.Gal

                          Cross Canonicalization for domains with same menu

                          sharing menu items

                          I have a client who took 3 pages from its main website and made them into their own domains. So that now, for example,
                          www.mainsite.com/page
                          redirects to
                          www.page.com This is so users can be given access to the content on that specific page with ease.
                          Now, www.page.com has the same menu items as www.mainsite.com, so that users who select the menu items on www.page.com will be circled back to the main site. But this means that there are now different URLs for these pages.
                          ie:
                          On www.mainsite.com there is: www.mainsite.com/menu-item
                          (the content resides here) And on www.page.com there is: www.page.com/menu-item
                          (Which is basically "scaffolding" to support the page and a means to get around, so to speak.This is to make any and all pages accessible at either domain. ) I have only seen this type of URL on the Moz campaign crawl. In the real world, when a user selects a menu item from the www.page.com, it will circle back to www.mainsite.com/menu-item SEO-wise, should I use cross-canonicalization to point www.page.com/menu-item to www.mainsite.com/menu-item? Or would this be splitting hairs since these are only seen on the Moz crawl?

                          Technical SEO | Oct 25, 2024, 4:35 PM | Shrine.SEO.Gal
                          0
                        • SamaritansPurse

                          Domain Masking SEO Impact

                          I hope I am explaining this correctly. If I need to provide any clarity please feel free to ask. We currently use a domain mask on an external platform that points back to our site. We are a non-profit and the external site allows users to create peer-to peer fundraisers that benefit our ministry. Currently we get many meta issues related to this site as well as broken links when fundraisers expire etc. We do not have a need to rank for the information from this site. Is there a way to index these pages so that they are not a part of the search engine site crawls as it relates to our site?

                          Technical SEO | Feb 18, 2019, 9:38 AM | SamaritansPurse
                          0
                        • wfm-uk

                          Lost ranking after domain switch

                          I recently migrated from https://whitefusemedia.com to https://whitefuse.com. The website URL structure and content remained the same and I followed all the best practice guidance regarding checks on the new domain and appropriate 301 redirects. I have seen traffic drop by about 50% and the traffic that is still coming through is mainly coming through links still listed by Google under the old domain (https://whitefusemedia.com). Is this normal? Should I expect to see this bounce back, or is there anything I can do now to regain the rankings?

                          Technical SEO | Nov 25, 2023, 1:42 PM | wfm-uk
                          0
                        • SO_UK

                          Company name ranking

                          Hi all, I hope somebody can share their thoughts on the below. A web designer launched my client's new website and I have been tasked with the SEO. I was approached with an immediate problem, www.clientswebsite.co.uk was ranking 9th for their company name after being indexed by Google. The search results above www.clientswebsite.co.uk were related to my client but not all, for example a direct competitor was also ranking. I have been working on the SEO for 2-3 weeks and I just managed to get to 3rd position for the company name, and then www.clientswebsite.co.uk disappeared from page 1! And now instead, an irelevant sub page is now ranking for the company name on page 2 (a contact page). I have checked and the home page is still indexed (did a site: check). The only problem software picks up is a redirect chain (http://homepage -> http://www.homepage  -> https://homepage) the web developers said it wouldn't impact rankings (when I asked them to edit the htaccess file to fix it) I've listed below the SEO tasks I completed whilst attempting to rank the company name: I set up analytics and webmaster tools, in which I set up preferred domain (www) Added a sitemap Edited meta data making sure company name was included I contacted the websites above www.clientswebsite.co.uk that were relevant and asked them to place a link linking to their new website, I was successful with a couple of these. I placed www.clientswebsite.co.uk on all of their social media profiles I reformatted headers on their home page, making sure the H1 included my client's company name I found 2 extra versions of my client's home page (not exact copies, but very similar content) that had been published, so I decided to 301 redirect these to the correct home page Activated SSL and forced to HTTPS I would really appreciate it if anyone could share their thoughts here, whether it be explanations or possible solutions Adam

                          Technical SEO | Dec 27, 2018, 4:15 PM | SO_UK
                          0
                        • RG_SEO

                          Does a subdomain benefit from being on a high authority domain?

                          I think the title sums up the question, but does a new subdomain get any ranking benefits from being on a pre-existing high authority domain. Or does the new subdomain have to fend for itself in the SERPs?

                          Technical SEO | Feb 12, 2015, 8:19 AM | RG_SEO
                          0
                        • waqid

                          Clients domain expired - rankings lost - repurchased domain - what next?

                          Its only been 10 days and i have repurchased the domain name/ renewed. The who is info, website and contact information is all still the same. However we have lost all rankings and i am hoping that our top rankings come back. Does anyone have experience with such a crappy situation?

                          Technical SEO | Nov 14, 2014, 7:39 AM | waqid
                          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 | Feb 16, 2013, 4:42 PM | fabrizzio
                          0
                        • TrevorMcKendrick

                          301 Redirect with an Exact Domain name Match

                          My Client had a site that ranked for a pretty competitive two word phrase, but for a variety of reasons had to transfer the site to a different domain name (with none of the previous keywords). We've 301'd everything just fine to the new site, but our traffic for that two word phrase, as well as related long tail traffic, is beginning to drop. Could the drop be related to something that we didn't do well in the transfer? Or is it due to the new domain name now not being an exact match? Sitenote question: Our Google Analytics is still set up for the former domain name and shows data just fine. Is there any reason to switch GA to the new domain? What are the pros/cons? Much thanks in advance!

                          Technical SEO | Dec 7, 2011, 7:16 AM | TrevorMcKendrick
                          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.