All static pages on HTML website - URL's end with .html - Is this bad?

XrumerGeek

Supreme Member
Jr. VIP
Joined
Nov 14, 2011
Messages
1,461
Reaction score
1,622
At present, on a HTML website I have created, all my URL's end in .html, and the pages don't load without it.

How much of an issue does this cause? Thinking in terms of best practices.

I figured I could edit .htaccess to make sure nobody misses the page by omitting the .html using something like;

Code:
RewriteRule ^page1$ /page1.html? [L,R=301]

I would do this for each and every page. Time spent is not a factor, as there are only 33 pages on-site and any additionals will be few and far between in the future, if any.

Thoughts on this? Or can someone explain a better solution.

Thank you.
 
It doesn't really matter if your pages end with .html or not as long as the address is entered correctly.
Nowadays, it's rare to see those pages but I think it's just for simplicity.
 
I wouldn't necessarily conclude it's bad, but one could make an argument that it looks "dated" or "unprofessional".

On the other hand, who is gonna manually type your pages and thus 404 because they didn't type ".html"? Probably no one. In that sense, I wouldn't worry.

If you wanna go the .htaccess route, you don't need to do it manually. You can just do this:
Code:
RewriteEngine On

# Check if the requested URL corresponds to a .html file
RewriteCond %{REQUEST_FILENAME}.html -f

# Rewrite the URL to serve the .html file
RewriteRule ^(.*)$ $1.html [L]

If you're using NGINX, you could do something like this in the actual server configuration instead:
Code:
location / {
    # Try to serve the file without .html, then fall back to adding .html
    try_files $uri $uri.html =404;
}

Hope this helps.
 
RewriteEngine On # Check if the requested URL corresponds to a .html file RewriteCond %{REQUEST_FILENAME}.html -f # Rewrite the URL to serve the .html file RewriteRule ^(.*)$ $1.html [L]

Legend, that worked a treat. Am I looking at potential duplicate content though as with this solution it seems that the page works without .html - and the browser doesn't show .html. So are there now two versions (.html and non .html) serving the same content or is it seen as one? Or am I misunderstanding this aspect?

Hearing your point also about it potentially looking dated and oldhat.
 
I use python scripts that build html pages with html extensions and there is no special problem about this, pages index well.
 
Am I looking at potential duplicate content though as with this solution it seems that the page works without .html - and the browser doesn't show .html. So are there now two versions (.html and non .html) serving the same content or is it seen as one?

The rule I've given you will rewrite links with no .html in them if a file with .html exists, but you will still be able to access them with .html. If that counts for duplicate, then yes.

If you want to have just the extension-less version, you can do something like this:
Code:
RewriteEngine On

# Redirect direct .html requests to the extension-less URL
RewriteCond %{THE_REQUEST} "\.html" [NC]
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

# Allow access to .html files only without the extension
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]

I don't have an Apache server running to test this right now, but it should in theory:
  • Serve test.html when the user goes to /test
  • Redirect /test.html to /test with 301 Permanently Moved so that you don't have this "duplication"
I think that second bit is important if you have good search placement, etc.

Hope this helps.
 
I use python scripts that build html pages with html extensions and there is no special problem about this, pages index well.

I assume that any link juice will flow also because of the redirect - so it won't matter if people link to .html or no html - similar to 301'ing a domain.
 
The rule I've given you will rewrite links with no .html in them if a file with .html exists, but you will still be able to access them with .html. If that counts for duplicate, then yes.

If you want to have just the extension-less version, you can do something like this:
Code:
RewriteEngine On

# Redirect direct .html requests to the extension-less URL
RewriteCond %{THE_REQUEST} "\.html" [NC]
RewriteRule ^(.*)\.html$ /$1 [R=301,L]

# Allow access to .html files only without the extension
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [L]

I don't have an Apache server running to test this right now, but it should in theory:
  • Serve test.html when the user goes to /test
  • Redirect /test.html to /test with 301 Permanently Moved so that you don't have this "duplication"
I think that second bit is important if you have good search placement, etc.

Hope this helps.

This looks good, will test this tomorrow and report back. Thanks for the help, and welcome to the forum. You'll be an asset.
 
Back
Top