Moz Q&A is closed.
After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.
Remove html file extension and 301 redirects
- 
					
					
					
					
 Hi Recently I ask for some work done on my website from a company, but I am not sure what they've done is right. 
 What I wanted was html file extensions to be removed like
 /ash-logs.html to /ash-logs
 also the index.html to www.timports.co.uk
 I have done a crawl diagnostics and have duplicate page content and 32 page title duplicates. This is so doing my head in please helpThis is what is in the .htaccess file <ifmodule pagespeed_module="">ModPagespeed on 
 ModPagespeedEnableFilters extend_cache,combine_css, collapse_whitespace,move_css_to_head, remove_comments</ifmodule><ifmodule mod_headers.c="">Header set Connection keep-alive</ifmodule> <ifmodule mod_rewrite.c="">Options +FollowSymLinks -MultiViews</ifmodule> DirectoryIndex index.html RewriteEngine On 
 #Rewrite valid requests on .html files RewriteCond %{REQUEST_FILENAME}.html -fRewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA] 
 #Return 404 on direct requests against .html filesRewriteCond %{REQUEST_URI} .html$ 
 RewriteCond %{QUERY_STRING} !rw=1 [NC]
 RewriteRule ^ - [R=404]AddCharset UTF-8 .html # <filesmatch “.(js|css|html|htm|php|xml|swf|flv|ashx)$”="">#SetOutputFilter DEFLATE #</filesmatch><ifmodule mod_expires.c="">ExpiresActive On 
 ExpiresByType image/gif "access plus 1 years"
 ExpiresByType image/jpeg "access plus 1 years"
 ExpiresByType image/png "access plus 1 years"
 ExpiresByType image/x-icon "access plus 1 years"
 ExpiresByType image/jpg "access plus 1 years"
 ExpiresByType text/css "access 1 years"
 ExpiresByType text/x-javascript "access 1 years"
 ExpiresByType application/javascript "access 1 years"
 ExpiresByType image/x-icon "access 1 years"</ifmodule><files 403.shtml="">order allow,deny allow from all</files> redirect 301 /PRODUCTS http://www.timports.co.uk/kiln-dried-logs 
 redirect 301 /kindling_firewood.html http://www.timports.co.uk/kindling-firewood.html
 redirect 301 /about_us.html http://www.timports.co.uk/about-us.html
 redirect 301 /log_delivery.html http://www.timports.co.uk/log-delivery.html redirect 301 /oak_boards_delivery.html http://www.timports.co.uk/oak-boards-delivery.html
 redirect 301 /un_edged_oak_boards.html http://www.timports.co.uk/un-edged-oak-boards.html
 redirect 301 /wholesale_logs.html http://www.timports.co.uk/wholesale-logs.html redirect 301 /privacy_policy.html http://www.timports.co.uk/privacy-policy.html redirect 301 /payment_failed.html http://www.timports.co.uk/payment-failed.html redirect 301 /payment_info.html http://www.timports.co.uk/payment-info.html
- 
					
					
					
					
 This looks good to me, the html pages are 301ing to the non .html versions.  
- 
					
					
					
					
 I think I've done it this is what I have found and added to my htaccess code. <ifmodule mod_rewrite.c=""> 
 Options +FollowSymLinks -MultiViews</ifmodule>DirectoryIndex index.html RewriteEngine On 
 RewriteBase /#removing trailing slash 
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)/$ $1 [R=301,L]#non www to www 
 RewriteCond %{HTTP_HOST} !^www.
 RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]#html 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^.]+)$ $1.html [NC,L]#index redirect 
 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/
 RewriteRule ^index.html$ http://www.timports.co.uk/ [R=301,L]
 RewriteCond %{THE_REQUEST} .html
 RewriteRule ^(.*).html$ /$1 [R=301,L]
- 
					
					
					
					
 I still have the internal error, thank you for your time in looking at this I will keep trying 
- 
					
					
					
					
 Hi, htaccess can be a pain and I will admit I usually manage what I am after with a bit of trial and error. Try the following, and if you have problems concentrate on the lines: RewriteCond %{THE_REQUEST} .html 
 RewriteRule ^(.*).html$ /$1 [R=301,L]I have added a redirect for index.html to root, and from non www to www and removed the last .html from the last list of _ to - redirects. Give it a shot, and keep that backup handy just in case. If no go, maybe one of the htaccess experts around can step in and have a look, I am not 100% sure what some of those other rules are doing to be honest! <ifmodule pagespeed_module="">ModPagespeed on 
 ModPagespeedEnableFilters extend_cache,combine_css, collapse_whitespace,move_css_to_head, remove_comments</ifmodule><ifmodule mod_headers.c="">Header set Connection keep-alive</ifmodule> AddCharset UTF-8 .html<filesmatch ".(js|css|html|htm|php|xml|swf|flv|ashx)$"="">#SetOutputFilter DEFLATE 
 #</filesmatch><ifmodule mod_expires.c="">ExpiresActive On 
 ExpiresByType image/gif "access plus 1 years"
 ExpiresByType image/jpeg "access plus 1 years"
 ExpiresByType image/png "access plus 1 years"
 ExpiresByType image/x-icon "access plus 1 years"
 ExpiresByType image/jpg "access plus 1 years"
 ExpiresByType text/css "access 1 years"
 ExpiresByType text/x-javascript "access 1 years"
 ExpiresByType application/javascript "access 1 years"
 ExpiresByType image/x-icon "access 1 years"</ifmodule><files 403.shtml="">order allow,deny allow from all</files> # mod_rewrite On only needed once 
 RewriteEngine On301 permanent redirect old underscore.html to new dash urlsredirect 301 /PRODUCTS http://www.timports.co.uk/kiln-dried-logs 
 redirect 301 /kindling_firewood.html http://www.timports.co.uk/kindling-firewood
 redirect 301 /about_us.html http://www.timports.co.uk/about-us
 redirect 301 /log_delivery.html http://www.timports.co.uk/log-delivery
 redirect 301 /oak_boards_delivery.html http://www.timports.co.uk/oak-boards-delivery
 redirect 301 /un_edged_oak_boards.html http://www.timports.co.uk/un-edged-oak-boards
 redirect 301 /wholesale_logs.html http://www.timports.co.uk/wholesale-logs
 redirect 301 /privacy_policy.html http://www.timports.co.uk/privacy-policy
 redirect 301 /payment_failed.html http://www.timports.co.uk/payment-failed
 redirect 301 /payment_info.html http://www.timports.co.uk/payment-info301 permanent redirect index.html to folderRewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)index.html?\ HTTP/ 
 RewriteRule ^(([^/]+/))index.html?$ http://www.timports.co.uk/$1 [R=301,L]301 permanent redirect non-www to wwwRewriteCond %{HTTP_HOST} !^(www.timports.co.uk)?$ 
 RewriteRule (.*) http://www.timports.co.uk/$1 [R=301,L]301 permanent redirect all .html to non .htmlRewriteCond %{THE_REQUEST} .html 
 RewriteRule ^(.*).html$ /$1 [R=301,L]
- 
					
					
					
					
 thanks Lyn, but that gave an 500 internal error, back up worked though 
- 
					
					
					
					
 Hi, I think you will only need this bit: #301 from example.com/page.html to example.com/page 
 RewriteCond%{THE_REQUEST}^[A-Z]{3,9}\ /..html\ HTTP/
 RewriteRule^(.).html$ /$1 [R=301,L]And you would replace this bit below with the above: Rewrite valid requests on .html files RewriteCond %{REQUEST_FILENAME}.html -fRewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA] 
 #Return 404 on direct requests against .html filesRewriteCond %{REQUEST_URI} .html$ 
 RewriteCond %{QUERY_STRING} !rw=1 [NC]
 RewriteRule ^ - [R=404]But leave the at the end of that section. htaccess files can be a bit picky, so be sure to keep a backup so you can quickly undo something if it is not working! 
- 
					
					
					
					
 Ok have got links to work again with old code, going to try this #example.com/page will display the contents of example.com/page.html RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteCond%{REQUEST_FILENAME}.html -f RewriteRule^(.+)$ $1.html [L,QSA] #301 from example.com/page.html to example.com/page RewriteCond%{THE_REQUEST}^[A-Z]{3,9}\ /..html\ HTTP/ RewriteRule^(.).html$ /$1 [R=301,L] where would I put this code in relation to what I already have in my htaccess file 
- 
					
					
					
					
 Thanks you for your reply, I have looked at the links you provided and tried replacing this RewriteEngine On # Rewrite valid requests on .html files RewriteCond %{REQUEST_FILENAME}.html -fRewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA] Return 404 on direct requests against .html filesRewriteCond %{REQUEST_URI} .html$ 
 RewriteCond %{QUERY_STRING} !rw=1 [NC]
 RewriteRule ^ - [R=404]with this, but it didn't work or I did something wrong. #example.com/page will display the contents of example.com/page.html RewriteCond%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteCond%{REQUEST_FILENAME}.html -f RewriteRule^(.+)$ $1.html [L,QSA] #301 from example.com/page.html to example.com/page RewriteCond%{THE_REQUEST}^[A-Z]{3,9}\ /..html\ HTTP/ RewriteRule^(.).html$ /$1 [R=301,L] Now www.timports.co.uk says this page cant be displayed so I tried to put it back to the previous .htaccess and still no links working I am so stuck 
- 
					
					
					
					
 Hi, Indeed there seems to be an issue with your redirects since the .html versions are still available on your site. Two things to check in the first instance: 1. The redirect line for the .html to non .html versions: Rewrite valid requests on .html files RewriteCond %{REQUEST_FILENAME}.html -fRewriteRule ^ %{REQUEST_URI}.html?rw=1 [L,QSA] I am not sure if this will work the way you want it. First of all a # at the beginning of this line means it is a comment and not processed so you seem to have the RewriteCond part of the statement as a comment (maybe this is just the forum formatting it wrong, but good to check). 
 You can check some other solutions for redirecting .html to non .html here: http://stackoverflow.com/questions/5730092/how-to-remove-html-from-url2. At the bottom of the file you have a bunch of 301 redirects like this: redirect 301 /kindling_firewood.html http://www.timports.co.uk/kindling-firewood.html Which are working as expected redirecting underscored urls to urls with dashes. But they are also redirecting to the .html version which means you will be getting into double redirects which is pointless in your case. Once you have the non .html redirects working as expected you should adjust these 301s to go to the non .html version like so: redirect 301 /kindling_firewood.html http://www.timports.co.uk/kindling-firewood Hope that helps! 
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 ToolsChat with the community about the Moz tools. 
- 
		
		SEO TacticsDiscuss the SEO process with fellow marketers 
- 
		
		CommunityDiscuss industry events, jobs, and news! 
- 
		
		Digital MarketingChat about tactics outside of SEO 
- 
		
		Research & TrendsDive into research and trends in the search industry. 
- 
		
		SupportConnect on product support and feature requests. 
Related Questions
- 
		
		
		
		
		
		What is the difference between 301 redirects and backlinks?
 i have seen some 301 redirects on my site billsonline, can anyone please explain the difference between backlinks and 301 redirects, i have read some articles where the writer was stating that 301 are not good for website. Technical SEO | | aliho0
- 
		
		
		
		
		
		301 Redirects, Sitemaps and Indexing - How to hide redirected urls from search engines?
 We have several pages in our site like this one, http://www.spectralink.com/solutions, which redirect to deeper page, http://www.spectralink.com/solutions/work-smarter-not-harder. Both urls are listed in the sitemap and both pages are being indexed. Should we remove those redirecting pages from the site map? Should we prevent the redirecting url from being indexed? If so, what's the best way to do that? Technical SEO | | HeroDesignStudio0
- 
		
		
		
		
		
		How to redirect 302 status to 301 status code using wordpress
 I just ran the link opportunity option within site explorer and it shows that 31 pages are currently in a 302 status. Should I try to convert the 302's to 301's? And what is the easiest way to do this? I see several wordpress plugins that claim to do 301 redirects but I don't know which to choose. Any help would be greatly appreciated! Technical SEO | | vmsolu0
- 
		
		
		
		
		
		Best & easiest way to 301 redirect on IIS
 Hi all, What is the best and easiest way to 301 redirect URLs on IIS server? I got access to the FTP and WordPress back office, but no access to the server admin. Is there an easy way to create 301 redirect without having to always annoy the tech in charge of the server? Thanks! Technical SEO | | 2MSens0
- 
		
		
		
		
		
		Removing Redirected URLs from XML Sitemap
 If I'm updating a URL and 301 redirecting the old URL to the new URL, Google recommends I remove the old URL from our XML sitemap and add the new URL. That makes sense. However, can anyone speak to how Google transfers the ranking value (link value) from the old URL to the new URL? My suspicion is this happens outside the sitemap. If Google already has the old URL indexed, the next time it crawls that URL, Googlebot discovers the 301 redirect and that starts the process of URL value transfer. I guess my question revolves around whether removing the old URL (or the timing of the removal) from the sitemap can impact Googlebot's transfer of the old URL value to the new URL. Technical SEO | | RyanOD0
- 
		
		
		
		
		
		Is it worth setting up 301 redirects from old products to new products?
 This year we are using a new supplier and they have provided us a product database of approx. 5k products. About 80% of these products were in our existing database but once we have installed the new database all the URLs will have changed. There is no quick way to match the old products with the new products so we would have to manually match all 5k products if we were were to setup 301 rules for the old products pointing to the new products. Of course this would take a lot of time. So the options are: 1. Is it worth putting in this effort to make the 301 rules? 2. Or are we okay just to delete the old product pages, let the SE see the 404 and just wait for it to index the new pages? 3. Or, as a compromise, should we 301 the old product page to the new category page as this is a lot quicker for us do do than redirecting to the new product page? Technical SEO | | indigoclothing0
- 
		
		
		
		
		
		How to safely reduce the number of 301 redirects / should we be adding so many?
 Hi All, We lost a lot of good rankings over the weekend with no obvious cause. Our top keyword went from p3 to p12, for example. Site speed is pretty bad (slower than 92% of sites!) but it has always been pretty bad. I'm on to the dev team to try and crunch this (beyond image optimisation) but I know that something I can effect is the number of 301 redirects we have in place. We have hundreds of 301s because we've been, perhaps incorrectly, adding one every time we find a new crawl error in GWT and it isn't because of a broken link on our site or on an external site where we can't track down the webmaster to fix the link. Is this bad practice, and should we just ignore 404s caused by external broken URLs? If we wanted to reduce these numbers, should we think about removing ones that are only in place due to external broken URLs? Any other tips for safely reducing the number of 301s? Thanks, all! Chris Technical SEO | | BaseKit0
- 
		
		
		
		
		
		301 Redirect vs Domain Alias
 We have hundreds of domains which are either alternate spelling of our primary domain or close keyword names we didn't want our competitor to get before us. The primary domain is running on a dedicated Windows server running IIS6 and set to a static IP. Since it is a static IP and not using host headers any domain pointed to the static IP will immediately show the contents of the site, however the domain will be whatever was typed. Which could be the primary domain or an alias. Two concerns. First, is it possible that Google would penalize us for the alias domains or dilute our primary domain "juice"? Second, we need to properly track traffic from the alias domains. We could make unique content for those performing well and sell or let expire those that are sending no traffic. It's not my goal to use the alias domains to artificially pump up our primary domain. We have them for spelling errors and direct traffic. What is the best practice for handling one or both of these issues? Technical SEO | | briankb0
 
			
		 
			
		 
			
		 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				