Abstract URLs with Apache .htaccess files

I moved my web pages to a new server, but neglected to copy my Apache .htaccess files. For WordPress, no problem, since the WordPress software itself reminds you of what .htaccess content you need. But for generic abstract URLs, such as letting users request www.example.com/foo and serve them www.example.com/foo.html, what do you do?

After several attempts, I found, as usual, the answer at Stackoverflow:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]

Leave a Comment

Your email address will not be published. Required fields are marked *