Hi, I have been trying to figure out how to remove the .html from the url as it's quite unattractive to see the .html extension at the end of the links. I don't think I have come across a single website that has .html anymore. I have googled how to do this and the only thing that seem to come up is .htaccess? Is this the best method to go about this or would you recommend something different. Do you have a reliable source or tutorial reference that I could follow? Thanks, Regards, Chris
Why don't you create index.html in each subdirectory? this way the server won't need to do the rewrite in every request. I mean this: /index.html /foo/index.html /foo/bar/index.html /wu/index.html So you have these URLs: http://example.com http://example.com/foo http://example.com/foo/bar http://example.com/wu You can do 301 redirects for the URLs ending in /index.html... surely there is a rewrite rule for this. I don't know if the best practice is doing this or using canonical.
Most sites run with PHP so there is no need for the index.html file in each directory. The only problem I see with this approach is the possibility of duplicate content if there are links to the index.html files. I'm doing this in my site; if this happens I'll use 301 redirects or canonical.
Hello @Web_Dev_Chris , You can redirect all .html extensions through .htaccess with the following code: RewriteEngine On #redirect index.html RewriteCond %{THE_REQUEST} ^.*/index RewriteRule ^(.*)index.html /$1 [R=301,L] #hide .html RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.html [NC,L] Code (markup): It is also recommended to redirect 404 pages like so: ErrorDocument 404 /.error/404.html Code (markup): You will need to create a folder under your public_html called .error or any other name you like. Within the folder create a 404.html which uses the template of your website. Now, when someone requests a page that doesn't exist, he'll be redirected to your custom 404 page. I will also share something interesting and probably many people will try to prove it's wrong. Maybe it is, maybe it's not. We have a small project that uses .html extensions and they are indexed and displayed in search engines as: example.com/article/example-title.html meanwhile : example.com/article/example-title responds with 404. We have some good ranking results on urls with .html extension at the end.