Trevis Rothwell's weblog

Almost, but not quite, entirely unlike tea

Abstract URLs with Apache .htaccess files

03 April 2021

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]