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
-
403 Errors Issue
Hi, all! I've been working with a Wordpress site that I inherited that gets little to no organic traffic, despite being content rich, optimized, etc. I know there's something wrong on the backend but can't find a satisfactory culprit. When I emulate googlebot, most pages give me a 403 error. Also, google will not index many urls which makes sense and is a massive headache. All advice appreciated! The site is https://www.diamondit.pro/ It is specific to WP Engine, using GES (Global Edge Security) and WPWAF
Technical SEO | | SimpleSearch0 -
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 -
Despite proper hreflang and lang attribute implementation using xml sitemaps, I'm seeing sitelinks from different countries. Any help please?
When someone searches for our brand in US, instead of only US links, users are served with canadian or iranian sitelinks. Despite we have properly implemented xml sitemaps with hreflangs, even we have implemented lang attribute in the head section of source code for every country. I'd be thankful for any advice.
Technical SEO | | eset0 -
Does anyone have experience using Attracta with a Miva Merchant website?
I am looking for more information on Attracta, which is now a certified app for Plesk and Parallels Automation. You can apparently install Attracta for Parallels from the Apps Catalog.
Technical SEO | | djlittman0 -
How do you fix soft 404 errors?
I'm getting soft 404 errors for a gallery on my site: http://chrle.us/MBKs yet when I visit the url: http://www.chrisboar.com/html/galleries/114/portfolio/weddings-1/0 the image/url is there. Not sure how to fix this. note we do redirect the site to the flash site and only use those URLs for SEO purposes. Maybe that is what is causing it. thanks
Technical SEO | | callmeed0 -
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);)/category/job-site-requirements/tag/cost-of-water/tag/irrigation-usage/tag/save-water/tag/standard-industry-practice/tag/water-use 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);)/tag/children-in-modern-world/tag/children/tag/childrens-day/tag/conservation-medicine/tag/ecowise-certified/tag/estonia/tag/extermination-service/tag/exterminator/tag/green-thumb/tag/hearts-pest-management/tag/higher-certification/tag/higher-education/tag/tartu/tag/united-states
Technical SEO | | GerryWeitz0 -
Duplicate Content Errors
Ok, old fat client developer new at SEO so I apologize if this is obvious. I have 4 errors in one of my campaigns. two are duplicate content and two are duplicate title. Here is the duplicate title error Rare Currency And Old Paper Money Values and Information.
Technical SEO | | Banknotes
http://www.antiquebanknotes.com/ Rare Currency And Old Paper Money Values and Information.
http://www.antiquebanknotes.com/Default.aspx So, my question is... What do I need to do to make this right? They are the same page. in my page load for default.aspx I have this: this.Title = "Rare Currency And Old Paper Money Values and Information."; And it occurs only once...0 -
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