• seohunters9

        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. Intermediate & Advanced SEO
        4. 6 .htaccess Rewrites: Remove index.html, Remove .html, Force non-www, Force Trailing Slash

        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.

        6 .htaccess Rewrites: Remove index.html, Remove .html, Force non-www, Force Trailing Slash

        Intermediate & Advanced SEO
        3
        4
        12079
        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.
        • NeatIT
          NeatIT last edited by

          i've to give some information about my website Environment

          1. i have static webpage in the root.

          2. Wordpress installed in sub-dictionary www.domain.com/blog/

          3. I have two .htaccess , one in the root and one in the wordpress
          folder.

          i want to

          • www to non on all URLs
          • Remove index.html from url
          • Remove all .html extension / Re-direct 301 to url
            without .html extension
          • Add trailing slash to the static webpages / Re-direct 301 from non-trailing slash
          • Force trailing slash to the Wordpress Webpages / Re-direct 301 from non-trailing slash

          Some examples

          domain.tld/index.html >> domain.tld/

          domain.tld/file.html >> domain.tld/file/

          domain.tld/file.html/ >> domain.tld/file/

          domain.tld/wordpress/post-name >> domain.tld/wordpress/post-name/

          My code in ROOT htaccess is

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

          RewriteEngine On
          RewriteBase /

          #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://domain.com/ [R=301,L]
          RewriteCond %{THE_REQUEST} .html
          RewriteRule ^(.*).html$ /$1 [R=301,L]</ifmodule>

          The above code do

          1. redirect www to non-www
          2. Remove trailing slash at the end (if exists)
          3. Remove index.html
          4. Remove all .html
          5. Redirect 301 to filename but doesn't add trailing slash at the end

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

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

            hi anyone please help I use this code but now getting 404 error. please help.

            i also remove this code again but still same issue.

            1 Reply Last reply Reply Quote 0
            • NeatIT
              NeatIT @Tom-Anthony last edited by

              Hi Tom,

              thanks for your reply.

              i have some problems

              the above code doesn't

              1 - Add trailing slash to the static webpages / Re-direct 301 from non-trailing slash

              so it should be http://ghadaalsaman.com/articles/ instead of http://ghadaalsaman.com/articles

              2 - Force trailing slash to the Wordpress Webpages / Re-direct 301 from non-trailing slash

              1 Reply Last reply Reply Quote 0
              • Tom-Anthony
                Tom-Anthony last edited by

                Hey NeatIT!

                I see you have a working solution there. Did you have a specific question about the setup?

                I did notice that your setup cane sometimes result in chaining 301 redirects, which is one area for possible improvement.

                Let me know how we can help! 🙂

                NeatIT 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

                • brandonegroup

                  Removing the Trailing Slash in Magento

                  Hi guys, We have noticed trailing slash vs non-trailing slash duplication on one of our sites. Example:
                  Duplicate: https://www.example.com.au/living/
                  Preferred: https://www.example.com.au/living So, SEO-wise, we suggested placing a canonical tag on all trailing slash pointing to non-trailing slash. However, devs have advised against removing the trailing slash from some URLs with a blanket rule, as this may break functionality in Magento that depends on the trailing slash. The full site would need to be tested after implementing a blanket rewrite rule. Is any other way to address this trailing slash duplication issue without breaking anything in Magento? Keen to hear from you guys. Cheers,

                  Intermediate & Advanced SEO | | brandonegroup
                  0
                • alphonseha

                  Google not Indexing images on CDN.

                  My URL is: http://bit.ly/1H2TArH We have set up a CDN on our own domain: http://bit.ly/292GkZC  We have an image sitemap: http://bit.ly/29ca5s3 The image sitemap uses the CDN URLs. We verified the CDN subdomain in GWT. The robots.txt does not restrict any of the photos: http://bit.ly/29eNSXv. We used to have a disallow to /thumb/ which had a 301 redirect to our CDN but we removed both the disallow in the robots.txt as well as the 301. Yet, GWT still reports none of our images on the CDN are indexed. The above screenshot is from the GWT of our main domain.The GWT from the CDN subdomain just shows 0. We did not submit a sitemap to the verified subdomain property because we already have a sitemap submitted to the property on the main domain name. While making a search of images indexed from our CDN, nothing comes up: http://bit.ly/293ZbC1While checking the GWT of the CDN subdomain, I have been getting crawling errors, mainly 500 level errors. Not that many in comparison to the number of images and traffic that we get on our website. Google is crawling, but it seems like it just doesn't index the pictures!? Can anyone help? I have followed all the information that I was able to find on the web but yet, our images on the CDN still can't seem to get indexed.

                  Intermediate & Advanced SEO | | alphonseha
                  0
                • Caro-O

                  Home page suddenly dropped from index!!

                  A client's home page, which has always done very well, has just dropped out of Google's index overnight!
                  Webmaster tools does not show any problem. The page doesn't even show up if we Google the company name. The Robot.txt contains: Default Flywheel robots file User-agent: * Disallow: /calendar/action:posterboard/
                  Disallow: /events/action~posterboard/ The only unusual thing I'm aware of is some A/B testing of the page done with 'Optimizely' - it redirects visitors to a test page, but it's not a 'real' redirect in that redirect checker tools still see the page as a 200. Also, other pages that are being tested this way are not having the same problem. Other recent activity over the last few weeks/months includes linking to the page from some of our blog posts using the page topic as anchor text. Any thoughts would be appreciated.
                  Caro

                  Intermediate & Advanced SEO | | Caro-O
                  0
                • MozAddict

                  Magento Trailing Slash URL Problem

                  Howdy Mozzers! Our magento store URL's are accessible with or without a trailing slash at the end. Canonical's and 301 redirects are not set up for one of them at the moment. Will this cause duplicate issue? Do we need to set canonical or 301 up? Which one is recommended? MozAddict

                  Intermediate & Advanced SEO | | MozAddict
                  0
                • khi5

                  Infinite Scrolling: how to index all pictures

                  I have a page where I want to upload 20 pictures that are in a slideshow. Idea is that pictures will only load when users scroll down the page (otherwise too heavy loading). I see documentation on how to make this work and ensure search engines index all content. However, I do not see any documentation how to make this work for 20 pictures in a slideshow. It seems impossible to get a search engines to index all such pictures, when it shows only as users scroll down a page. This is documentation I am already familiar with, and which does not address my issue:
                  http://googlewebmastercentral.blogspot.com/2014/02/infinite-scroll-search-friendly.html http://www.appelsiini.net/projects/lazyload http://luis-almeida.github.io/unveil/ thank you

                  Intermediate & Advanced SEO | | khi5
                  0
                • pano

                  Removing dashes in our URLs?

                  Hi Forum, Our site has an errant product review module that is resulting in about 9-10 404 errors per day on Google Webmaster Tools. We've found that by changing our product page URLs to only include 2 dashes, the module stops causing 404 errors for that page. Does changing our URL from "oursite.com/girls-pink-yoga-capri.html" to "oursite.com/girlspink-yoga-capri.html" hurt our SEO for a search for "girls pink yoga capri"? If so, by how much (assuming everthing else on the page is optimized properly) Thanks for your input.

                  Intermediate & Advanced SEO | | pano
                  0
                • MyNet

                  How To 301 Redirect .html pages

                  I need to redirect a page/URL that is purely .html to a new location.  I don't know how to do this.  All the redirects I can find are for server side code pages .php/.aspx etc.  From my understanding I can't put a server side redirect in a .html file.  I am hosting on a microsoft server, however the new page I am redirecting to is .php.  I am running some WordPress (.php) files on the server.  I need to make it redirect before the old page loads so visitors don't start reading something that is about to get redirected Can someone please help me?

                  Intermediate & Advanced SEO | | MyNet
                  0
                • ContentWriterMicky

                  How to resolve Duplicate Page Content issue for root domain & index.html?

                  SEOMoz returns a Duplicate Page Content error for a website's index page, with both domain.com and domain.com/index.html isted seperately. We had a rewrite in the htacess file, but for some reason this has not had an impact and we have since removed it. What's the best way (in an HTML website) to ensure all index.html links are automatically redirected to the root domain and these aren't seen as two separate pages?

                  Intermediate & Advanced SEO | | ContentWriterMicky
                  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.