tl;dr Yes, you can enable MultiViews
to serve extensionless URLs. ie. Where the file extension is omitted from a URL that would otherwise map to an existing file. However, be aware of potential conflicts with mod_rewrite.
the server won't even open links to the site that are missing a file extension
You make it sound that this should be normal (or expected) behaviour? It is not. On most (database driven / CMS) sites these days, this behaviour would be undesirable. MultiViews
is not enabled by default on Apache. It must be explicitly enabled.
As you have found, some shared hosts do appear to enable MultiViews
automatically for its customers. So, extensionless URLs "magically" work out of the box. However, if you then want to do something more complex and rewrite/redirect the URL using mod_rewrite then you can end up with some unexpected conflicts which can be confusing to debug. This would seem to be a reasonably common problem - StackOverflow in particular is littered with questions of this nature, where the solution is to simply disable MultiViews
(because it's been automatically enabled by the host).
The conflict with mod_rewrite comes about because mod_negotitation (which drives MultiViews
) runs before mod_rewrite. For example, when you request /article99
with MultiViews
enabled, mod_negotiation issues an internal subrequest for /article99.html
(for example). You can't intercept this with mod_rewrite, you will need to match against the resulting subrequest, ie. /article99.html
, not /article99
(which you might have expected since this is the URL the user actually requested and the only URL you actually see).
I want to double check that this is the proper way to do it
Well, it is one "way to do it". Yes, it is "proper". However, it is not the only way to do it. And is not always the correct way to do it. It depends on exactly what you are trying to do and what else you are already doing. But if it works for you; use it.
MultiViews
does more than simply append a file extension. The resource that is returned depends on the request (this is the "negotiation" part of mod_negotiation). And which is returned when you have article99.php
, article99.html
and article99.jpg
? And if the only file you have is article99.abc
then you'll likely get a 404 (unless you have a handler defined for .abc
files).
Also consider that, if you simply use MultiViews
, the file article99.html
(for example) is still accessible as well. So, you have the URLs /article99
and /article99.html
both returning the same resource. This is technically duplicate content - although is not necessarily a problem providing you ensure that the /article99
URL is the only URL that is ever referenced. As a minimum you should set a <link rel="canonical"
element pointing to the canonical URL, ie. /article99
.
.htm
,.html
,.php
, etc.). Your static resources (images, CSS, JS, etc.) should all have an extension. If you went extensionless for everything then you are increasing your dependency onMultiViews
, moving away to another method/system would be more complex and prone to error.