Hello Guest, if you read this, it means you are not registered. Click here to register a few simple steps, you will enjoy all the features of our Forum. Please note that nicknames are prohibited lewd or meaningless (no numbers or letters at random) and introduce yourself in the section for you to meet our community.
Rewrite .html using .htaccess - Blogs - GOZEN Host Forums
View RSS Feed

GOZEN Host blogs

Rewrite .html using .htaccess

Rate this Entry
by , 09-05-2015 at 08:33 AM (2508 Views)
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 build 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 been 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.

Submit "Rewrite .html using .htaccess" to Digg Submit "Rewrite .html using .htaccess" to del.icio.us Submit "Rewrite .html using .htaccess" to StumbleUpon Submit "Rewrite .html using .htaccess" to Twitter