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
-
Need help please with url guidelines.
Hi SEO PROS, I have a website and I am planing to change all the urls. I need to know what is the right way of making the urls. Here is some information. We are based in Brooklyn NY and we sell our services to Manhattan clients and Manhattan has few names. NY, NYC, Manhattan and NY. So by looking at my service area I came up with this url. http://www.signsny.com/brooklyn-ny/awnings this is my current url. http://www.signsny.com/sign-types/awnings-canopies-brooklyn-NYC. This is what I am planning to change it to. Please guide me to the right direction, so in future I don't have to re-do them again. Thanks Abie
Technical SEO | | signsny0 -
Client error 404
I have an 404 error but what does that mean? I go to the site and click on the link to exampleX.com there is no problem. What can it be? The error message http://www.example.com/www.example.com/exampleX.html
Technical SEO | | mato0 -
Getting 404 error when open the cache link of my site
My site is hazanstadservice.se and when I am trying to open this to check the cache date i got a 404 error from google. I don't know why ? The cache page url is http://webcache.googleusercontent.com/search?q=cache:j99uW96RuToJ:www.hazanstadservice.se/+&cd=1&hl=en&ct=clnk.
Technical SEO | | Softlogique0 -
Use of Multiple Tags
Hi, I have been monitoring some of the authority sites and I noticed something with one of them. This high authority site suddenly started using multiple tags for each post. And I mean, loads of tags, not just three of four. I see that each post comes with at least 10-20 tags. And these tags don't always make sense either. Let's say there is a video for "Bourne Legacy", they list tags like bourne, bourney legacy, bourne series, bourne videos, videos, crime movies, movies, crime etc. They don't even seem to care about duplicate content issues. Let's say the movie is named The Dragon, they would inclue dragon and the-dragon in tags list and despite those two category pages(/dragon and /the-dragon) being exactly the same now, they still wouldn't mind listing both the tags underneath the article. And no they don't use canonical tag. (there isn't even a canonical meta on any page of that site) So I am curious. Do they just know they have a very high DA, they don't need to worry about duplicate content issues? or; I am missing something here? Maybe the extra tags are doing more good than harm?
Technical SEO | | Gamer070 -
.htaccess and error 404
Hi, I permit to contact the community again because you have good and quick answer ! Yesterday, I lost the file .htaccess on my server. Right now, only the home page is working and the other pages give me this message : Not Found The requested URL /freshadmin/user/login/ was not found on this server Could you help me please? Thanks
Technical SEO | | Probikeshop0 -
A website that will not load on a particular computer? Help Me Please!
We took on a new client about two weeks ago, took them off a proprietary CMS, placed them on a WordPress site, optimized the site, etc. and were finishing up small details three days ago. My PC in my personal office all of a sudden would not load the site from a Google search, from a direct url, etc.
Technical SEO | | RobertFisher
Our office was using a D-Link wireless router but my PC is hardwired in the office. I cranked up my MacBook Pro with solid state drive (6 months old), got on wireless, and....site would not load. PC's and Macs in offices around me would all load the site. A search online brought up a fix for the PC and tried it - did not work, had lead dev try it - did not work, called a server side friend and he had never heard of such a thing. Every fix revolved around changing IP addresses, etc. I uninstalled my antivirus programs on my PC, installed every update that was outstanding, there was no new software installed on either box prior to problem. Can you help??? Is there any chance someone not associated with us and just looking for my client or someone entering a direct url could experience?0 -
Help with SEO
Hello, I am brand new to SEO and I'm learning on the go everyday. I am having issues with Google and getting any sort of ranking or analysis or even just traffic reports. I understand the site has never really been optimized so it might really not have any reports. So basically my real question is what helpful tricks or hints do you guys have that I can implement? Anything and everything helps. So far I have run the crawl diagnostics and I'm working on fixing the errors. Thanks fr your help.
Technical SEO | | Future130 -
404 help
Hello all, firstly let me apologize if this is the wrong place to ask this question. I have a site www.promptresponseaccidentmanagement.com which gets a 200ok when checked for crawl issues, however pages such as /whiplash-injury-compensation-claims.php , /road-traffic-accident-compensation-claims.php and quite a few more return a 404. That's fine (usually) as I can quite happily fix that most of the time. However if you actually go to those pages in your browser, or click through to them on any part of the site you will see that they are in fact not redirecting to a 404 and everything is fine!? Any body got any ideas? Best H
Technical SEO | | haydyn0