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. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. Add trailing slash after removing .html extention

    Add trailing slash after removing .html extention

    Technical SEO Issues
    6 3 712
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Uber_
      Uber_ last edited by

      My website is non www ,it has wordpress in subdirectory and some static webpages in the root and other subdirectory

      1. i want to remove .html extention from the webpages in the root and
      the others static webpages in subdirectory.
      2. add slash at the end.
      3. 301 redirect from non slash to url with slash.

      so it should be

      http://ghadaalsaman.com/articles.html to http://ghadaalsaman.com/articles/

      and

      http://ghadaalsaman.com/en/poem-list.html to http://ghadaalsaman.com/en/poem-list/

      the below code

      1. working with non slash at the end

      **2. **redirect 301 url with slash to non

      here's my .htaccess

      <ifmodule mod_rewrite.c="">Options +FollowSymLinks -MultiViews

      RewriteEngine On
      RewriteBase /</ifmodule>

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

      #www to non
      RewriteCond %{HTTP_HOST} ^www.(([a-z0-9_]+.)?domain.com)$ [NC]
      RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]

      #html
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([^.]+)$ $1.html [NC,L]

      #index redirect
      RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/
      RewriteRule ^index.html$ http://ghadaalsaman.com/ [R=301,L]
      RewriteCond %{THE_REQUEST} .html
      RewriteRule ^(.*).html$ /$1 [R=301,L]

      PS everything is ok with the wordpress , the problems with static pages only.

      Thanks in advanced

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

        Hi Uber_,

        Typically this is handled is by adding the following to your .htaccess file:

        RewriteCond %{REQUEST_FILENAME} !-f              <--looks like your version of this would also work fine.
        
        RewriteCond %{REQUEST_URI} !index.php             <---This is very optional. If there are any .php files you don't want to be rewritten add their .endpath here.
        
        RewriteCond %{REQUEST_URI} !(.*)/$                   <----Looks like you have this, which determines which url doesn't have a trailing slash.
        
        RewriteRule ^(.*)$ http://ghadaalsaman.com.com/$1/ [L,R=301]    <----This would add a trailing slash and then redirect to the new URL.
        
        Highly recommend you add the last line because both of your / and non / ending urls are populating (which could cause duplicate content issues). This will also help with allocating proper page authority.
        
        Hope this helps,
        B
        
        NeatIT Uber_ 2 Replies Last reply Reply Quote 0
        • NeatIT
          NeatIT @BMullz last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • Uber_
            Uber_ @BMullz last edited by

            i tried that code and not working

            <ifmodule mod_rewrite.c=""> 
            Options +FollowSymLinks -MultiViews

            RewriteEngine On 
            RewriteBase /</ifmodule>

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

            #www to non
            RewriteCond %{HTTP_HOST} ^www.(([a-z0-9_]+.)?domain.com)$ [NC]
            RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]

            #html
            RewriteCond %{REQUEST_FILENAME} !-f 
            RewriteCond %{REQUEST_FILENAME} !-d 
            RewriteRule ^([^.]+)$ $1.html [NC,L]

            #index redirect 
            RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/ 
            RewriteRule ^index.html$ http://ghadaalsaman.com/ [R=301,L]
            RewriteCond %{THE_REQUEST} .html 
            RewriteRule ^(.*).html$ /$1 [R=301,L]

            #moz
            RewriteRule ^(.*)$ http://ghadaalsaman.com.com/$1/ [L,R=301]

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

              Can you please try the above but delete:

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

              Let me know if that works.

              NeatIT 1 Reply Last reply Reply Quote 0
              • NeatIT
                NeatIT @BMullz last edited by

                Not Working

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • Trailing slash URLs and canonical links
                  GhillC
                  GhillC
                  0
                  3
                  1.5k

                • Should I add my html sitemap to Robots?
                  Libra_Photographic
                  Libra_Photographic
                  0
                  3
                  72

                • Will removing the trailing slash impact my SEO?
                  Alick300
                  Alick300
                  0
                  3
                  5.7k

                • Google Search Results and Trailing Slash
                  mememax
                  mememax
                  0
                  2
                  217

                • Trailing Slashes on Home Pages
                  Marcus_Miller
                  Marcus_Miller
                  0
                  9
                  6.4k

                • Issues with trailing slash url
                  tomcraig86
                  tomcraig86
                  0
                  2
                  462

                • Duplicate Content For Trailing Slashes?
                  KeriMorgret
                  KeriMorgret
                  0
                  5
                  434

                • Trailing slash 301 redirect code
                  jamesjackson
                  jamesjackson
                  0
                  10
                  5.4k

                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 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                • Accessibility
                • Terms of Use
                • Privacy