• 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 Wordpress to remove trailing slashes?

        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 Wordpress to remove trailing slashes?

        Technical SEO
        6
        9
        45435
        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.
        • james-tb
          james-tb last edited by

          I've searched around quite a bit for a solution here, but I can't find anything. I apologize if this is too technical for the forum.

          I have a Wordpress site hosted on Nginx by WP Engine. Currently it resolves requests to URLs either with or without a trailing slash.

          So, both of these URLs are functional:

          <code>mysite.com/single-post</code>
          

          and

          <code>mysite.com/single-post/</code>
          

          I would like to remove the trailing slash from all posts, forcing mysite.com/single-post/ to redirect to mysite.com/single-post. I created a redirect rule on the server:

          ^/(.*)/$ -> /$1

          and this worked well for end-users, but rendered the admin panel inaccessible. Somewhere, Wordpress is adding a trailing slash back on to the URL mysite.com/wp-admin, resulting in a redirect loop. I can't see anything obvious in .htaccess.

          Where is this rule adding a trailing slash to 'wp-admin' established?

          Thanks very much

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

            WPEis run on a base server using Apache with a Nginx proxy so you can use the WP engine  301 redirect system built-in or you can simply add a redirect to the HTAccess file. If you would like to use a tool to do this I recommend this one another alternative is to ask WP engine to make a change for you.https://www.aleydasolis.com/htaccess-redirects-generator/non-slash-vs-slash-urls/ApacheJust copy to your htaccess:```
            https://example.com/page/

            **https://example.com/page** 
            ``` 
            <label for="nonslash">**Slash to Non-Slash URLs**</label>
            
            > <ifmodule mod_rewrite.c="">RewriteEngine on
            > RewriteCond %{REQUEST_FILENAME} !-d
            > RewriteRule ^(.*)/$ /$1 [L,R=301]</ifmodule>
            
            **Non-Slash to Slash URLs**
            
            ```
            ****Apache**
            https://example.com/page**
            

            https://example.com/page/

            
            > <ifmodule mod_rewrite.c="">RewriteEngine on
            > RewriteCond %{REQUEST_FILENAME} !-f
            > RewriteRule ^(.*[^/])$ /$1/ [L,R=301]</ifmodule>
            
            

            USEING Nginx to do

            **https://example.com/page/**
            

            https://example.com/page

            
            As you see, there is one tiny difference between those two URLs, and it’s the trailing slash at the end. In order to avoid duplicate content, if you are using Nginx you can **remove the trailing slash from Nginx** URLs.
            
            Place this inside your virtual host file in the server {} block configuration:
            
            > ```
            > rewrite ^/(.*)/$ /$1 permanent;
            > ```
            
            Full example:
            
            > ```
            > server {
            > listen 80;
            > server_name www.mysite.com;
            > rewrite ^/(.*)/$ /$1 permanent;
            > }
            > ```
            
            All done, now Nginx will remove all those trailing slashes.
            
            

            USEING Nginx to do
            https://example.com/page
            https://example.com/page/

            
            Add a trailing slash by placing this inside your virtual host file in the server {} block configuration:
            
            > ```
            > rewrite ^(.*[^/])$ $1/ permanent;
            > ```
            
            Full example:
            
            > ```
            > server {
            > listen 80;
            > server_name www.mysite.com;
            > rewrite ^(.*[^/])$ $1/ permanent;
            > }
            > ```
            
            From now on, Nginx should add your trailing slash automatically to every url
            
            *   https://www.scalescale.com/tips/nginx/add-trailing-slash-nginx/
            *   https://www.scalescale.com/tips/nginx/nginx-remove-trailing-slash/
            
             I hope this helps,
            
            Tom
            1 Reply Last reply Reply Quote 0
            • ATP
              ATP last edited by

              Hi John, sorry ive been on leave so not checked back on the  forums.

              Glad it looks like its working for you. I dont think the comments do anything except signify where word press has begun writing to the .htaccess (i dont run wordpress so can't be sure). Normally comments do nothing but signify something useful to the user.

              I can try to breakdown the code a little for you, but my htaccess isn't fantastic so its by no means complete.

              Firstline:  RewriteCond%{REQUEST_FILENAME}!-d

              RewriteCond% = This says use this condition if....
              {REQUEST_FILENAME}!-d =  ... is NOT a directory

              RewriteRule^(.*)/$ /$1 [L,R=301]
              I believe this bit takes a snapshot of the url upto the final / then rewrites it to that snapshot.

              The combination of these must mean it doesn't affect your wordpress admin directory. I know this code can break if your install is within a directory (as is discussed in the stackover flow link) but they have provided a solution for that in that topic. I would say test if on your live website to make complete sure it will work as this may be slightly different to your local install. Have a back-up ready just incase it doesn't.

              Make sure you check every url including

              Homepage
              Pages
              Posts
              Category Pages
              Sub Category Pages
              Post Pages
              Any images or files

              To make sure it is working as expected on all of them.

              1 Reply Last reply Reply Quote 1
              • james-tb
                james-tb last edited by

                Thanks so much, ATP! It looks like writing the condition into .htaccess does the trick—at least for my local install. Is this because the commands located within the

                BEGIN WordPress

                END WordPress

                comments only apply to URLs outside of the WP admin area?

                Thanks again, ATP—that was a very thorough and helpful response!

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

                  Hi John

                  Did ATP's solution help you out? Let us know if we can look into this further!

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

                    Hi John,

                    I asked something similar myself something myself but im on the Magento platform. This should matter as the solution wasn't platform specific. It just involved editing htaccess file. If your up for editing your .htacccess file then it could be of some use. The topic URL is below and it contains multiple solutions for editing and removing the / and the debugging process we went through along the way. (Courtesy of Andy and Dirk) Hopefully its of some use to you

                    https://a-moz.groupbuyseo.org/community/q/cms-pages-multiple-urls

                    SUMMARY:
                    If you know how to edit your .htaccess and your ready to dive straight in this code should do it.

                    RewriteCond%{REQUEST_FILENAME}!-d
                    RewriteRule^(.*)/$ /$1 [L,R=301]

                    If you want the page with explanations and walk-through please see the original topic as editing your htaccess  badly can cause all sorts of errors.

                    Edit: I realised i was probably a tiny bit lazy and should of probably included this link which is the original link i got sent from stackoverflow with instructions on how to to edit your .htaccess file.

                    http://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url

                    Dirks answer later in the post offer guidance on applying it to certain parameters which should prove helpful if your still having loop problems with the admin page.

                    1 Reply Last reply Reply Quote 2
                    • james-tb
                      james-tb last edited by

                      Thanks for the replies, Donna, Martijn. I am running Yoast and considered adding the trailing slash, but:

                      -Most of the inbound links we have are to URLs with no slash

                      -The slash style seems a little dated in general-few sites use them these days.

                      I'd really love to just figure out how to solve the issue a little closer to the root.

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

                        Hi John,

                        It seems obvious, but why not go for a adding a trailing slash to every URL instead or removing it, would solve your issues at least.

                        1 Reply Last reply Reply Quote 1
                        • DonnaDuncan
                          DonnaDuncan last edited by

                          Are you using the yoast SEO plugin? There is a setting under Advanced > Permalinks that forces a trailing slash onto URLs. I'd try looking at that first.

                          1 Reply Last reply Reply Quote 1
                          • 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

                          • Dreamrealemedia

                            Move a Wordpress Site to HTTPS with Bluehost

                            HI Guys, do you think that the following guide is enoght to move a bluehost wordpress site to https in a seo best practive way? https://www.shoutmeloud.com/free-ssl-certificate-bluehost-hosting.html Basically their steps are: Install SSL on Bluehost panel Install Really Simple SSL Wp Plugin Edit Your .htacess File & Add The Code For HTTP To HTTPS Redirection Update All HTTP URLs In Database To HTTPS Using Search and Replace Plugin Use Broken Link Checker plugin & use its redirection module to find links to 3rd party sites with HTTP that should now be HTTPS. Last thing to do Submit your new HTTPS site to Google Search Console & submit your sitemap. Update your profile link on Google Analytics. Update your website links on social media profiles & anywhere else they exist. This step you can do in pieces in the coming days. Read this guide to learn more about HTTP to HTTPS migration & fixing mixed content. If you disabled Who.Is guard for your domain name, you can enable it now. Do you know a better practical guide for wordrpess? in term of usefull plugins to handle the migration? Tx to everyone!

                            Technical SEO | | Dreamrealemedia
                            0
                          • acktivate

                            Why add .html to WordPress pages?

                            A site I may take over has a plugin that adds .html to the pages. I searched online but I’ve only found how to add it rather than why to add it. Is it needed? If I remove it, I’ll have to be careful with SEO / indexed pages and redirects.  The site is running 3.x.x and 90% of the plugins have not been updated in over 5 years including this one. Before I update to 4.7.x, I am trying to understand the landscape (pros / cons) on why something could be used and if I need to find a suitable replacement for it.

                            Technical SEO | | acktivate
                            2
                          • adamjack

                            How to remove Parameters from Google Search Console?

                            Hi All, Following are parameter configuration in search console - Parameters - fl
                            Does this parameter change page content seen by the user? - Yes, Changes, reorders, or narrows page content.
                            How does this parameter affect page content? - Narrow
                            Which URLs with this parameter should Googlebot crawl? - Let Googlebot decide (Default) Query - Actually it is filter parameter. I have already set canonical on filter page. Now I am doing tracking of filter pages via data layer and tag manager so in google analytic I am not able to see filter url's because of this parameter. So I want to delete this parameter. Can anyone please help me? Thanks!

                            Technical SEO | | adamjack
                            0
                          • Deacyde

                            Canonical homepage link uses trailing slash while default homepage uses no trailing slash, will this be an issue?

                            Hello, 1st off, let me explain my client in this case uses BigCommerce, and I don't have access to the backend like most other situations. So I have to rely on BG to handle certain issues. I'm curious if there is much of a difference using domain.com/ as the canonical url while BG currently is redirecting our domain to domain.com. I've been using domain.com/ consistently for the last 6 months, and since we switches stores on Friday, this issue has popped up and has me a bit worried that we'll loose somehow via link juice or overall indexing since this could confuse crawlers. Now some say that the domain url is fine using / or not, as per - https://a-moz.groupbuyseo.org/community/q/trailing-slash-and-rel-canonical But I also wanted to see what you all felt about this. What says you?

                            Technical SEO | | Deacyde
                            0
                          • rijwielcashencarry040

                            Remove sitemap, effect ranking?

                            We are considering to remove our sitemap because it doesn't display the right structure. Will it affect current rankings if we remove the sitemap en continuing without a sitemap? Thanks

                            Technical SEO | | rijwielcashencarry040
                            0
                          • allstatetransmission

                            Removing images from site and Image Sitemap SEO advice

                            Hello again, I have received an update request where they want me to remove images from this site (as of now its a bunch of thumbnails) current page design: http://1stimpressions.com/portfolio/car-wraps/ and turn it into a new design which utilized a slider (such as this): http://1stimpressions.com/portfolio/ They don't want the thumbnails on the page anymore. My question is since my site has a image sitemap that has been indexed will removing all the images hurt my SEO greatly? What would the recommended steps to take to reduce any SEO damage be, if so? Thank you again for your help, always great and very helpful feedback! 🙂 cheers!

                            Technical SEO | | allstatetransmission
                            0
                          • CsmBill

                            How do I add "noindex" or "nofollow" to a link in Wordpress

                            It's been a while since I've SEOed a Wordpress site. How do I add "nofollow" or "noindex" to specific links? I highlight the anchor text in the text editor, I click the "link" button. I could have sworn that there used to be an option in the dialogue box that pops up.

                            Technical SEO | | CsmBill
                            0
                          • JollyBoy

                            How to force a trailing slash after the domain name

                            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

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