Rewrite .html using .htaccess
We all know that static sites or otherwise called HTML sites are no longer that familiar… or maybe they are?
With all recent Google algorithm changes you might find that some pages are built using static HTML just for speed… in cases like that it’s more likely that you will end up having URL’s looking like this: mydomain.com/blog.html
Well.. no worries, as we have a fix for this and it’s easy!
Using .htaccess and making sure that the following rules do not conflict with any other rules you might have not only you will manage to remove the .html file extension from your URL’s but we also create a permanent redirection for all .html URL’s in order to avoid being penalized by Google.
# This tag ensures the rewrite module is loaded # enable the rewrite engine RewriteEngine On # Set your root directory RewriteBase / # remove the .html extension RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP RewriteRule (.*)\.html$ $1 [R=301] # remove index and reference the directory RewriteRule (.*)/index$ $1/ [R=301] # remove trailing slash if not a directory RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} /$ RewriteRule (.*)/ $1 [R=301] # forward request to html file, **but don't redirect (bot friendly)** RewriteCond %{REQUEST_FILENAME}.html -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.html [L]
Need any help? Don’t hesitate to ask on our forums or just post a comment.
Do you wanna try this yourself? Order a VPS from GoZEN Host and start testing in a couple of minutes.
Leave a Reply