Web Programming Notes

July 6, 2007

Apache ModRewrite all .html > index.php

Filed under: Apache, PHP — admin @ 4:47 pm

Put the following line into a file called .htaccess.

RewriteRule ^.*\.html$ index.php [qsa]

All URLs requesting a resource with a .html extension will actually be a request for index.php.

e.g. http://domainname.tld/xyz.html?dog=cat becomes http://domainname.tld/index.php?dog=cat 

I believe the [qsa] arguments stand for “query string append” which means that any GET parameters in the original request will also be appended to the new rewritten request. 

If you are using PHP, you can use the $_SERVER superglobal to find out the orginal page being requested.

Powered by WordPress