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
-
Please who can help me rank my website www.shopdocuments.com ?
Hi , i bought my website this month , i built it myself now i want it to grow seo on google pages and stuff tried google ads but they always block my account don't know why so somebody help me please any company? individual willing to work it for me ? even if paid company no problem
Technical SEO | | planetdocs1 -
Help! added WWW to wordpress site and now lost SEO ranking
Hi there Everyone! I have recently added a www to my wordpress website by going to settings>general and adding "www" to the wordpress address and the site address. After i did that i lost my SEO ranking, and also that MOZ is detecting that im getting site crawl issues stating that i have duplicate pages. an example is below: http://www.mefco.co.nz/news http://mefco.co.nz/news any ideas on how to fix this?
Technical SEO | | jfactor0 -
Google not found errors in webmaster tool help
Hi, Google Webmaster tools sent me a few messages recently about the jump in the number of 'not found' errors. From 0 to 290 errors, ouch. I know what it's from but I think Google is seeing things. We developed another page/subdomain we're working on with links back to the root domain. Basically a complete list of articles page that lists each article and links back to the root domain. Not sure what Google is crawling but the links that would result in a 'not found' error aren't there. Will these disappear over time? Thanks for the help!
Technical SEO | | astahl110 -
Can anyone help me understand why google is "Not Selecting" a large number of my webpages to include when crawling my site.
When looking through my google webmaster tools, I clicked into the advanced settings under index status and was surprised to see that google has marked around 90% of my pages on my site as "Not Selected" when crawling. Please take a look and offer any suggestions. www.luxuryhomehunt.com
Technical SEO | | Jdubin0 -
404 Error from site - is this normal?
I have been trying to clean up any 404 errors. We keep getting the following: URL /include/vdimgck.php referring domain http://www.856d.c@m/plus/feedback.php rendered domain unclickable by adding the "@" since I do not know if it is safe. I just turned off the trackbacks and pings in the blog since I saw it was producing duplicate content and from what I read it is not worth keeping those with Wordpress. is vdimgck.php anything some here instantly recognizes ? It tops all our 404 errors, seems like a lot of requests. Thanks!
Technical SEO | | Force70 -
What tool can i use to get the true speed of my site
hi, i am trying to get the true speed of my site. i want to know how fast www.in2town.co.uk is but the tools that i am using are giving me different readings. http://tools.pingdom.com/fpt/#!/DkHoNWmZh/www.in2town.co.uk says the speed is 1.03s http://gtmetrix.com/reports/www.in2town.co.uk/i4EMDk34 says my speed is 2.25s and http://www.vertain.com/m.q?req=cstr&reqid=dAv79lt8 says it is 4.36s so as you can see i am confused. I am trying to get the site as fast as possible, but need to know what the correct speed is so i can work on things that need changing to make it faster. can anyone also let me know what speed i should be working for. many thanks
Technical SEO | | ClaireH-1848860 -
I'm getting a Duplicate Content error in my Pro Dashboard for 2 versions of my Homepage. What is the best way to handle this issue?
Hi SEOMoz,I am trying to fix the final issues in my site crawl. One that confuses me is this canonical homepage URL fix. It says I have duplicate content on the following pages:http://www.accupos.com/http://www.accupos.com/index.phpWhat would be the best way to fix this problem? (...the first URL has a higher page authority by 10 points and 100+ more inbound links).Respectfully Yours,Derek M.
Technical SEO | | DerekM880 -
Where to get expert SEO help?
I joined SEOmoz knowing very little about SEO (it turns out even less than I thought!) I signed up because my business website that had be ranking very well for years made a fast and furious fall to the purgatory of page 2, 3, whatever. We'll I've definitely learned a lot and made a several changes that have helped. Specifically link building (directory submissions) and eliminating duplicate content. But we're still far below where we used to be and I've done everything I can do without making a career change to SEO. I've hired a few offshore SEOs to help but they have all failed to live up to their promises. So, I would love to find a GOOD SEO that can 1. Fix the remaining on-page technical issues in our CMS website (Business Catalyst), and 2. help us develop an SEO strategy for the next year. (I prefer not to post the name of the website for competitive reasons) Our keywords are really not very competitive at all due to the uniqueness of the business. Where should I look for help? Thanks
Technical SEO | | Placeboo0