How to remove .html
from the URL of a static page?
Also, I need to redirect any url with .html
to the one without it. (i.e. www.example.com/page.html
to www.example.com/page
).
How to remove .html
from the URL of a static page?
Also, I need to redirect any url with .html
to the one without it. (i.e. www.example.com/page.html
to www.example.com/page
).
To remove the .html extension from your urls, you can use the following code in root/htaccess :
NOTE: If you want to remove any other extension, for example to remove the .php extension, just replace the html everywhere with php in the code above.
I think some explanation of Jon's answer would be constructive. The following:
checks that if the specified file or directory respectively doesn't exist, then the rewrite rule proceeds:
But what does that mean? It uses regex (regular expressions). Here is a little something I made earlier...
I think that's correct.
NOTE: When testing your
.htaccess
do not use 301 redirects. Use 302 until finished testing, as the browser will cache 301s. See https://stackoverflow.com/a/9204355/3217306Update: I was slightly mistaken,
.
matches all characters except newlines, so includes whitespace. Also, here is a helpful regex cheat sheetSources:
http://community.sitepoint.com/t/what-does-this-mean-rewritecond-request-filename-f-d/2034/2
https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules
With .htaccess under apache you can do the redirect like this:
As for removing of .html from the url, simply link to the page without .html
This should work for you:
Thanks for your replies. I have already solved my problem. Suppose I have my pages under http://www.yoursite.com/html, the following .htaccess rules apply.
I use this .htacess for removing .html extantion from my url site, please verify this is correct code: