Mobile app version of topseosmo.com
Login or Join
Megan663

 query : Enabling Multiviews is how you make a web server able to open links with missing extensions? I'm in the process of switching web hosts. My old host was of the beginner-friendly 'kid gloves'

@Megan663

Posted in: #Htaccess #UrlRewriting #WebDevelopment #WebHosting #Webserver

I'm in the process of switching web hosts. My old host was of the beginner-friendly 'kid gloves' variety. I had less control, but it took care of a lot of things behind the scenes.

My new web host will allow me to do more with my site, but only the bare minimum is set up out of the gate. The web server won't do anything extra unless I specifically tell it to. I now need to learn a bunch of new "obvious" knowledge about managing a server.

When testing my site on the new host one thing I quickly realized is the server won't even open links to the site that are missing a file extension (e.g., example.com/article99)

Newbie me is trying to figure out how to set up the server to be able to go "Okay, this link to /photo37 has no extension, but I see there's an /photo37.png here in the directory. That must be what the link is referring to, so I'll open that".

From what I've been able to research so far the way to do this is to enable MultiViews. When I add Options +multiviews to my .htaccess file it seems to do the trick. But I want to double check that this is the proper way to do it, and that I'm not missing something obvious. Any help or links to resources are much-appreciated.

10.01% popularity Vote Up Vote Down


Report

Login to follow query

More posts by @Megan663

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

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.

10% popularity Vote Up Vote Down


Report

Back to top | Use Dark Theme