How to make example.com/about show example.com/about.html? (Apache2)

What is the best option to go when trying to have example.com/about show example.com/about.html, and without changing the url to /about.html. Right now i’m trying to the following code it just returns an 404 Error.

RewriteRule ^/about$ https://example.com/about.html [R=301,L]

Edit #1
To w3dk i currently do have multiviews enable but i still get a 404 error. Here is my current current setup in VirtualHost

<Directory /var/www/public_html>
    Options All +MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Answer

Instead of using mod_rewrite to internally rewrite the request, you could just use MultiViews (mod_negotiation) instead:

Options +MultiViews

mod_rewrite allows you to do more complex URL rewritting, however, if all you are doing is removing the file extension then MultiViews will suffice – it is what it’s designed for.

When you make a request for /about (a URL/file without an extension in a valid directory) then with MultiViews enabled, mod_negotiation will search for a file that matches the expected mime-type and return that as an internal request.

UPDATE:

Options All +MultiViews

This is not valid syntax (I assume you must be on Apache 2.2, as this would fail with an error during startup on Apache 2.4). As noted in the Apache docs:

Warning
Mixing Options with a + or - with those without is not valid syntax and is likely to cause unexpected results.

To express All and MultiViews you would need two directives:

Options All
Options +MultiViews

All is the default (on Apache 2.2) so this might not be necessary. However, it would be preferable to specify just the options you require in a single directive, for example:

Options FollowSymLinks Includes MultiViews

Attribution
Source : Link , Question Author : dotconnor , Answer Author : MrWhite

Leave a Comment