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
    • SEO Q&A
    • Webinars, Whitepapers, & Guides
  • Blog
  • Why Moz
    • Agency Solutions
    • Enterprise Solutions
    • Small Business Solutions
    • Case Studies
    • 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.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    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.

    • SEO Q&A

      Insights & discussions from an SEO community of 500,000+.

    Unlock flexible pricing & new endpoints
    Moz API

    Unlock flexible pricing & new endpoints

    Find your plan
  • Blog
  • Why Moz
    • 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.

    • Case Studies

      Explore how Moz drives ROI with a proven track record of success.

    • 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 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
45.4k
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.
  • james-tb
    james-tb last edited by Aug 17, 2015, 7:02 PM

    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 Nov 13, 2018, 2:01 PM Nov 13, 2018, 1:49 PM

      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
      • topic:timeago_earlier,3 years
      • ATP
        ATP last edited by Aug 20, 2015, 4:09 PM Aug 20, 2015, 5:22 AM

        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 Aug 19, 2015, 12:00 PM Aug 19, 2015, 12:00 PM

          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 Aug 19, 2015, 1:38 AM Aug 19, 2015, 1:38 AM

            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 Aug 19, 2015, 11:51 AM Aug 18, 2015, 12:36 PM

              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://moz.com/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 Aug 18, 2015, 11:13 AM Aug 18, 2015, 11:13 AM

                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 Aug 18, 2015, 4:03 AM Aug 18, 2015, 4:03 AM

                  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 Aug 18, 2015, 12:41 AM Aug 18, 2015, 12:41 AM

                    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
                    1 out of 9
                    • First post
                      1/9
                      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

                    • MarketHubb

                      Help Setting Up 301 Redirects from Coldfusion Site to Wordpress Site.

                      I have created a new website and need to redirect all of the previous pages to the new one. The old website was built in coldfusion and the new site is built in wordpress. One of the pages I'm trying to redirect is www.norriseal.com/products.cfm to http://norrisealwellmark.com/products/. This is what I have in my .htaccess file <ifmodule mod_rewrite.c="">Options +FollowSymlinks
                      RewriteEngine On
                      RewriteBase /
                      Redirect 301 /products.cfm http://norrisealwellmark.com/products/</ifmodule> The result of this redirect is http://norrisealwellmark.com/products.cfm How do I prevent the .cfm from appending to the destination URL?

                      Technical SEO | Jan 13, 2017, 4:00 PM | MarketHubb
                      1
                    • 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 | Sep 14, 2015, 5:40 AM | TimHolmes
                      0
                    • TomNYC

                      Should we change the publish date in WordPress when updating a post?

                      Hi everyone, We're going through some of our old posts in our WordPress blog and updating them, adding new information, new links, and photos. My question: If we update the posts significantly, should we also update the "published" date to today? If we only correct some typos or a dead link, we don't touch the date. However, if we've done some real work on the post, we'd like to update the published date in order to bring it to the top of our blog feed and draw new attention to the post. However, I'm a little nervous that this could be seen by Google as spammy, as it's not technically a new post and the URL already exists in Google's index of our site. Here's an example of a post that was published several years ago and then updated a few week's ago with new information (and a new date stamp): http://www.eurocheapo.com/blog/barcelona-tip-five-cheap-eats-under-e6.html Any thoughts on this? Thanks, Tom

                      Technical SEO | Aug 25, 2014, 4:24 PM | TomNYC
                      0
                    • CalicoKitty2000

                      Wordpress versus html and google ranking

                      My current SEO has always recommended that I take my site to wordpress.  I really don't want to move to wordpress.  I don't like it... I just like writing code in raw html, css, and script.  I feel like I have more control that way. Wordpress just seems like a platform for blogs (I have my blog in wordpress). My question is, do wordpress websites typically rank better? Is there benefit to moving to it?

                      Technical SEO | May 31, 2014, 10:50 AM | CalicoKitty2000
                      0
                    • TomLondon

                      Pages removed from Google index?

                      Hi All, I had around 2,300 pages in the google index until a week ago. The index removed a load and left me with 152 submitted, 152 indexed? I have just re-submitted my sitemap and will wait to see what happens. Any idea why it has done this? I have seen a drop in my rankings since. Thanks

                      Technical SEO | Mar 25, 2013, 5:36 PM | TomLondon
                      0
                    • RyanOD

                      Removing Redirected URLs from XML Sitemap

                      If I'm updating a URL and 301 redirecting the old URL to the new URL, Google recommends I remove the old URL from our XML sitemap and add the new URL. That makes sense. However, can anyone speak to how Google transfers the ranking value (link value) from the old URL to the new URL? My suspicion is this happens outside the sitemap. If Google already has the old URL indexed, the next time it crawls that URL, Googlebot discovers the 301 redirect and that starts the process of URL value transfer. I guess my question revolves around whether removing the old URL (or the timing of the removal) from the sitemap can impact Googlebot's transfer of the old URL value to the new URL.

                      Technical SEO | May 5, 2021, 4:56 AM | RyanOD
                      0
                    • JaredMumford

                      Removing URL Parentheses in HTACCESS

                      Im reworking a website for a client, and their current URLs have parentheses. I'd like to get rid of these, but individual 301 redirects in htaccess is not practical, since the parentheses are located in many URLs. Does anyone know an HTACCESS rule that will simply remove URL parantheses as a 301 redirect?

                      Technical SEO | Nov 26, 2012, 6:35 PM | JaredMumford
                      0
                    • SharewarePros

                      Notice of DMCA removal from Google Search

                      Dear Mozer's Today I get from Google Webmaster tools a "Notice of DMCA removal" I'll paste here the note to get your opinions "Hello, Google has been notified, according to the terms of the Digital Millennium Copyright Act (DMCA), that some of your materials allegedly infringe upon the copyrights of others. The URLs of the allegedly infringing materials may be found at the end of this message. The affected URLs are listed below: http://www.freesharewaredepot.com/productpages/Ultimate_Spelling__038119.asp" So I perform these steps: 1. Remove the page from the site (now it gives 404). 2. Remove it from database (no listed on directory, sitemap.xml and RSS) 3. I fill the "Google Content Removed Notification form" detailing the removal of the page. My question is now I have to do any other task, such as fill a site reconsideration, or only I have to wait. Thank you for your help. Claudio

                      Technical SEO | Sep 3, 2012, 12:08 AM | SharewarePros
                      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
                    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.