How to format the URL of .html page to remove extension with .htaccess? (WordPress)

So I have a custom created .html page in my website’s root folder (along with WP) and I want to be able to open it in a standard WordPress URL format, in other words without the .html extension at the end.

Bear in mind I know nothing about regular expressions or .htaccess, so I will give you concrete example:

Read More

When I type in mydomain.com/specialpage I want it to load mydomain.com/specialpage.html, but keep the originally typed URL format (without extension)

Related posts

2 comments

  1. RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(specialpage)/?$ /$1.html [L,NC]
    

    This appears to be working. Just had to put it above other default rules WordPress came with.

  2. If you have multiple pages, you can do it like this instead:

    RewriteEngine On
    
    # Check to see if a .html file exists for this request.
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteCond %{REQUEST_URI} !/$ # Prevent internal recursion
    
    # If so, then use serve that file.
    RewriteRule ^(.+)$ $1.html [NC,L]
    

    A note about trailing slashes: You won’t be able to do that here, as it will include it in the request filename, thus checking to see if specialpage/.html exists, which is not what you want.

Comments are closed.