Hi anyone please help I use this code but now getting 404 error. please help.
-
#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.
-
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.
-
URL Redirection for index.html
Your code snippet seems to be redirecting requests forindex.html
to the root domain. This part of the code looks fine and shouldn't be causing any 404 errors. -
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 likeabout.html
,contact.html
, andservicearea.html
. -
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
, andservicearea.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.
-
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.
-
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. -
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. -
-
Thank you guys, for your help it helped my problem to slove. I restore my pages back.
-
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.
-
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
-
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?
-
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]
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
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.
Related Questions
-
Getting a ton of "not found" errors in Webmaster tools stemming from /plugins/feedback.php
So recently Webmaster tools showed a million "not found" errors with the url "plugins/feedback.php/blah blah blah." A little googling helped me find that this comes from the Facebook comment box plugin. Apparently some changes recently have made this start happening. The question is, what's the right fix? The thread I was reading suggested adding "Disallow: /plugins/feedback.php" to the robots.txt file and marking them all fixed. Any ideas?
Technical SEO | | cbrant7770 -
Authority site drastic ranking drop after google https switch. Please Help!
Hi Mozers. Since Google switched to the https version, our company website (http://we.register.it) indexing switched to the https version (https://www.register.it). After that the ranking on Google dropped for almost every keyword. The site is very old and got a great authority and PR 7. It ranked for same keywords for very long time On each page from years there is the correct meta rel canonical. No spam, and WMT is ok. Could you please help? The internal links are all in http, and in https. If you are https are in https (they are all relatives) No changes have been made and the subdomain is in that way from 8 years: the main url has always been http://we.register.it Google started this indexing switch around the 15 October
Technical SEO | | luca_cash0 -
HTTP 500 Internal Server Error, Need help
Hi, For a few days know google crawlers have been getting 500 errors from our dedicated server whenever they try to crawl the site. Using the "Fetch as Google" tool under health in webmaster tools, I get "Unreachable page" every time I fetch the homepage. Here is exactly what the google crawler is getting: <code>HTTP/1.1 500 Internal Server Error Date: Fri, 21 Jun 2013 19:52:27 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 X-Pingback: [http://www.communityadvocate.com/xmlrpc.php](http://www.communityadvocate.com/xmlrpc.php) Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> My url is [http://www.communityadvocate.com](http://www.communityadvocate.com/)</code> and here's the screenshot from Goolge webmater http://screencast.com/t/FoWvqRRtmoEQ How can i fix that? Thank you
Technical SEO | | Vmezoz0 -
Types of SEO Help
I have a web site that is going well but I think it could be better as far as usability and design. Also, I am sure an SEO professional would have some things to do to optimize. It seems though, that all the SEO companies either want to have along term contract or they don't work with my technology. Does anyone know of a company that would take my Visual Studio/C# project and tweak it for usability, design and SEO features for an hourly or set price?
Technical SEO | | Banknotes0 -
Does this content get indexed?
A lot of content on this site is displayed in pop up pages. Eg. Visit the Title page http://www.landgate.wa.gov.au/corporate.nsf/web/Certificate+of+Title To access the sample report or fee details, the info is shown in a pop up page with a strange url. Example: http://www.landgate.wa.gov.au/corporate.nsf/web/Certificate+of+Title+-+Fee+Details I can't see any of these pages being indexed in Google or other search engines when I do a site search: http://www.landgate.wa.gov.au/corporate.nsf/web/Certificate+of+Title+-+Fee+Details Is there a way to get this content indexed besides telling the client to restructure this content?
Technical SEO | | Bigheadigital0 -
Increase in authorization permission errors error after site switch
We launched our new site 2 days ago , since site was down for 12 hours for maintenance, we saw google webmaster tool shows this error . Since then google hasnt crawled, its been 36 hours. Do we need to do anyting? We have close to a million page google crawled before and I am wondering if this will effect anything.
Technical SEO | | tpt.com0 -
Getting multiple errors for domain.com/xxxx/xxxx/feed/feed/feed/feed...
A recent SEOMoz crawl report is showing a bunch 404's and duplicate page content on pages with urls like http://domain.com/categories/about/feed/feed/feed/feed/feed and on and on. This is a wordpress install. Does anyone know what could be causing this or why SEOMoz would be trying to read these non-existent feed pages?
Technical SEO | | Brandtailers0