Skip to content
    Moz logo Menu open Menu close
    • Products
      • Moz Pro
      • Moz Pro Home
      • Moz Local
      • Moz Local Home
      • STAT
      • Moz API
      • 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.

      Discover Brand Authority
      Moz Pro

      Discover Brand Authority

      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.

      What is your Brand Authority?
      Moz

      What is your Brand Authority?

      Take the quiz
    • 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+.

      June 3 & 4, 2024, Seattle
      MozCon

      June 3 & 4, 2024, Seattle

      Get tickets
    • 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: Moz Pro

      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. Hi anyone please help I use this code but now getting 404 error. please help.

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

    Technical SEO
    4
    7
    1049
    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.
    • 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.

      homepage and service.html page is working, but the rest pages like about.html, servicearea.html, and contact.html is not working showing 404 error.

      and also when you type this URL. generalapplianceserice.ca/about.html

      generalapplianceserice.ca/contact.html

      generalapplianceserice.ca/servicearea.html

      it automatically remove the .HTML extension and shows 404 error, the pages name in root directory is same.

      these pages work like generalapplianceservice.ca and generalapplianceservice.ca/services

      why?

      i also remove this code again but still same issue.

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

        It seems like you're experiencing issues with URL redirection and page access in your website's .htaccess file. Let's break down the problem and address it step by step.

        1. URL Redirection for index.html
          Your code snippet seems to be redirecting requests for index.html to the root domain. This part of the code looks fine and shouldn't be causing any 404 errors.

        2. Removing .html Extension
          The second part of your code is meant to remove the .html extension from URLs. However, it seems to be causing the 404 errors for pages like about.html, contact.html, and servicearea.html.

        3. Troubleshooting
          Here are a few things you can check and try to resolve the issue:

          • Ensure that the .htaccess file is placed in the root directory of your website.
          • Verify that mod_rewrite is enabled on your server.
          • Check file permissions to ensure that the .htaccess file is readable by the server.
          • Make sure that the pages about.html, contact.html, and servicearea.html exist in the root directory of your website.
          • Verify that the file names are spelled correctly and match the URLs you're trying to access.
        4. Alternative Approach
          If you're still encountering issues, you might consider an alternative approach to removing the .html extension. Instead of using mod_rewrite rules, you can configure your web server (e.g., Apache) to handle URL rewriting.

          For example, in Apache, you can use the following configuration in your virtual host or server configuration file:

          <IfModule mod_rewrite.c>
              RewriteEngine On
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteCond %{REQUEST_FILENAME}\.html -f
              RewriteRule ^(.*)$ $1.html [NC,L]
          </IfModule>
          

          This configuration will serve requests without the .html extension if the corresponding .html file exists in the root directory.

        5. Testing
          After making any changes, be sure to clear your browser cache and test the URLs again to see if the issue has been resolved.

        6. Further Assistance
          If you're still having trouble, you may need to provide more details about your server environment (e.g., Apache version, hosting provider) for further assistance. Additionally, consulting your hosting provider's support team or a web development professional could also be beneficial in resolving the issue.

        Suppose you have the following files in the root directory of your website:
        index.html
        about.html
        contact.html
        servicearea.html
        And you want to remove the .html extension from URLs while ensuring that the pages are accessible without it.
        Ensure .htaccess file exists: First, make sure you have an .htaccess file in the root directory of your website.
        Enable mod_rewrite: Check if mod_rewrite is enabled on your server. You can do this by creating a PHP file (e.g., info.php) with the following content:
        php
        <?php
        phpinfo();
        ?>
        Access this file through your web browser (e.g., https://installationandrepairs.com/info.php) and search for "mod_rewrite". If it's enabled, you should see it listed.
        Edit .htaccess file: Open your .htaccess file and add the following code:
        apache
        <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME}.html -f
        RewriteRule ^(.*)$ $1.html [NC,L]
        </IfModule>

        Testing: Once you've made the changes, clear your browser cache and test the URLs without the .html extension. For example:
        https://installationandrepairs.com/ should display the index.html page.
        https://installationandrepairs.com/about should display the about.html page.
        https://installationandrepairs.com/contact should display the contact.html page.
        https://installationandrepairs.com/servicearea should display the servicearea.html page.
        If everything is configured correctly, you should be able to access your pages without the .html extension, and you shouldn't encounter any 404 errors.
        Remember to remove the info.php file after you've checked if mod_rewrite is enabled, as it may contain sensitive information about your server configuration. Additionally, always keep backups of your files before making changes to your website's configuration.

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

          Thank you guys, for your help it helped my problem to slove. I restore my pages back.

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

            In addition to the advice and tips you have already received here (in general: be super careful with .htaccess / httpd.conf files, and revert to previous versions if you see unexpected behaviour) one additional tip is to consider turning on logging while you debug the problem.

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

              Carefull with what your doing. I think you should revert in the first place if your not setting up a 301 moved status. Because of that, you could lose the (indexed) rankings for your index.html page. What you can do is a manual redirect, i.e

              redirect 301 /index.html /

              This moves (including the ranks) the index.html page back to / the root of your domain. You could also setup a canonical URL > https://moz.com/learn/seo/canonicalization

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

                hi, thanks for your reply, Jeroen, I was trying to remove the content duplication, that occurred

                when I was crawling my website with the Moz pro tool.

                its showed me two pages, generalapplianceservice.ca, and generalapplianceservice.ca/index.html

                I was just trying to remove the index.html page.

                so I used the above code. and start getting an error of 404, in 3 to 4 pages of the website.   the pages were correct in the root page, the name of pages was also correct.

                the page was this generalapplianceserice.ca/about.html, before the code and after the code, it removed the generalapplianceserice.ca/about

                .HTML extension from the URL and showing a 404 error.

                right now I used Errordocument 404 code in htaccess file. for handling 404 pages.

                also the change the page name. but I need the same page back.

                any help?

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

                  Could you tell us what you are trying to archieve in the first place? Your script proberly wont work, because domain.com is'nt replaced with your own domain, second it's code is only valid for HTTP instead of https, so to work with what we have here, try this:

                  RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/
                  RewriteRule ^index.html$ https://generalapplianceservice.ca/ [R=301,L]
                  RewriteCond %{THE_REQUEST} .html
                  RewriteRule ^(.*).html$ /$1 [R=301,L]

                  roynguyen 1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    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

                  • tiromedia

                    Should we use Cloudflare

                    Hi all, we want to speed up our website (hosted in Wordpress, traffic around 450,000 page views monthly), we use lots of images. And we're wondering about setting up on Cloudflare, however after searching a bit in Google I have seen some people say the change in IP, or possible sharing of Its with bad neighbourhoods, can really hit search rankings. So, I was wondering what the latest thinking is on this subject, would the increased speed and local server locations be a boost for SEO, moreso than a potential loss of rankings for changing IP? Thanks!

                    Technical SEO | | tiromedia
                    1
                  • AliMac26

                    Duplicate content and 404 errors

                    I apologize in advance, but I am an SEO novice and my understanding of code is very limited. Moz has issued a lot (several hundred) of duplicate content and 404 error flags on the ecommerce site my company takes care of. For the duplicate content, some of the pages it says are duplicates don't even seem similar to me. additionally, a lot of them are static pages we embed images of size charts that we use as popups on item pages. it says these issues are high priority but how bad is this? Is this just an issue because if a page has similar content the engine spider won't know which one to index? also, what is the best way to handle these urls bringing back 404 errors? I should probably have a developer look at these issues but I wanted to ask the extremely knowledgeable Moz community before I do 🙂

                    Technical SEO | | AliMac26
                    0
                  • jthompson0513

                    Do you get penalized in search results when you use a heading tag, but it's not technically a heading (used for emphasis)?

                    Do you get penalized in search results when you use a heading tag, but it's not technically a heading? My clients are using heading tags for text they want to emphasize and make stand out. Does this affect search rankings for SEO?

                    Technical SEO | | jthompson0513
                    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://moz.com/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
                  • sqmedia

                    Use of Location Folders

                    I'd like to understand the pro's and con's of using a location subfolder as an SEO strategy (example: http://sqmedia.us/Dallas/content-marketing.html), where the /Dallas folder is holding all of my keyword rich page titles. The strategy is to get local-SEO benefits from the use of the folder titled /Dallas (a folder which is unnecessary in the over all structure of this site), but how much is this strategy taking away from the page-title keyword effectiveness?

                    Technical SEO | | sqmedia
                    0
                  • ttb

                    Yoast settings help

                    I could use some real help here in my Yoast settings. I had some great settings before but we switched servers and it looks like we lost all our settings. I've taken some screenshots and I'm hoping someone can help! http://d.pr/i/chNQ http://d.pr/i/51TY http://d.pr/i/io7S http://d.pr/i/nak http://d.pr/i/acon The site is run by a couple guys. Please help!

                    Technical SEO | | ttb
                    0
                  • TRICORSystems

                    SEOMoz Crawling Errors

                    I recently implemented a blog using WordPress on our website. I didn't use WordPress as the CMS for the rest of our site just the blog portion. So as an example I installed Wordpress in http://www.mysite/blog/" not in the root. My error report in SEOMoz went from 0 to 22e. The Moz bot  or crawler that SEOMoz uses is reporting a ton of 4xx errors to strang links that shouldn't exist anywhere on the site. Example: Good link - http://www.mysite/products.html Bad link reported by SEOMoz - http://www.mysite/blog/my-first-post/products.html I've also noticed that my page speed as become much slower as reported by Google. Does anybody know what could be happening here? I know that typically it's better to install WordPress in the root and use it to control the entire site but I was under the gun to get a blog out. Thanks

                    Technical SEO | | TRICORSystems
                    0
                  • GerryWeitz

                    Why do I get duplicate content errors just for tags I place on blog entries?

                    I the SEO MOZ crawl diagnostics for my site, www.heartspm.com, I am getting over 100 duplicate content errors on links built from tags on blog entries.  I do have the original base blog entry in my site map not referencing the tags. Similarly, I am getting almost 200 duplicate meta description errors in Google Webmaster Tools associated with links automatically generated from tags on my blog.  I have more understanding that I could get these errors from my forum, since the forum entries are not in the sitemap, but the blog entries are there in the site map. I thought the tags were only there to help people search by category.  I don't understand why every tag becomes its' own link.  I can see how this falsely creates the impression of a lot of duplicate data. As seen in GWT: Pages with duplicate meta descriptions Pages [Customer concerns about the use of home water by pest control companies.](javascript:dropInfo('zip_0div', 'none', document.getElementById('zip_0zipimg'), 'none', null);)/ca​teg​ory​/jo​b-s​ite​-re​qui​rem​ent​s/ta​g/c​ost​-of​-wa​ter/ta​g/i​rri​gat​ion​-us​age/ta​g/s​ave​-wa​ter/ta​g/s​tan​dar​d-i​ndu​str​y-p​rac​tic​e/ta​g/w​ate​r-u​se 6 [Pest control operator draws analogy between Children's Day and the state of the pest control industr](javascript:dropInfo('zip_1div', 'none', document.getElementById('zip_1zipimg'), 'none', null);)/ta​g/c​hil​dre​n-i​n-m​ode​rn-​wor​ld/ta​g/c​hil​dre​n/ta​g/c​hil​dre​ns-​day/ta​g/c​ons​erv​ati​on-​med​ici​ne/ta​g/e​cow​ise​-ce​rti​fie​d/ta​g/e​sto​nia/ta​g/e​xte​rmi​nat​ion​-se​rvi​ce/ta​g/e​xte​rmi​nat​or/ta​g/g​ree​n-t​hum​b/ta​g/h​ear​ts-​pes​t-m​ana​gem​ent/ta​g/h​igh​er-​cer​tif​ica​tio​n/ta​g/h​igh​er-​edu​cat​ion/ta​g/t​art​u/ta​g/u​nit​ed-​sta​tes

                    Technical SEO | | GerryWeitz
                    0
                  Moz logo
                  • Contact
                  • Community
                  • Free Trial
                  • Terms & Privacy
                  • Accessibility
                  • Jobs
                  • Help
                  • News & Press
                  • MozCon
                  © 2021 - 2024 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.

                  Looks like your connection to Moz was lost, please wait while we try to reconnect.