Remove .html Extension From Every Url

Hi there,

This should be easy with .htaccess but for some reason I am struggling.

I want for example that:


always redirect to


My URL manager config is

'urlManager' => array(

            'urlFormat' => 'path',            

            'showScriptName' => false,


I am playing with my .htaccess the closest I got to something is

RewriteCond %{REQUEST_URI} \.html$

RewriteRule ^(.*)\.html$ $1 [R=301,L]

But I get a funny result (at least it did remove the html…):


Anyway I think there is something Yii specific that is causing a problem.

Any idea?




You may use like,

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)$ $1.html [NC,L]


Thank you for your suggestion Ghanshyam, I tried that but I get:

The system is unable to find the requested action "contact.html".

Anybody? I still cannot find a solution, this seems to be a trivial thing though…

Yii will not serve your static files its complaining about action not found if you trying to fake .html in your actions use the suffix property of urlmanager

'urlManager' => array(

            'urlFormat' => 'path',            

            'showScriptName' => false,



Thanks alirz23, but this is not what I am trying to do. This above will add .html to all my URLs inside the website.

I want that all my actions/link to have no .html in the URL. But if the user by mistake adds .html it is still understood, and the URL is stripped from the .html.

Any url rewrite specialist?