print 

Mara flatfile CMS

Extensionless URLs

Some webmasters prefer URLs to display without extensions such as .htm, .html or .php

There are two ways of achieving this. The method used by most of the mainstream CMS is URL rewriting. Whilst more flexible, this method is problematic in that the rewrite rules may interfere with access to files other than Mara content on the same webspace. We used parametric references and URL rewriting on the earliest inhouse version of Mara, and basically it was a constant source of aggro. We decided that the next version would avoid URL rewriting if at all possible. Hence one of the main reasons for the change to real URLs.

Where real URLs are used to reference pages, as opposed to index.php parameters, by far the simpler method is to enable Multiviews in the .htaccess file. This is achieved by adding +Multiviews to the Options line. For example:

.htaccess
Options +Multiviews -Indexes

A URL typed without an extension will then be treated as if it were a webpage bearing one of the typical extensions, and the first document of same name and a suitable type in the directory loaded. You could then strip off the extensions from all your menu entries, which would be a huge chore for a long menu... but thankfully a timesaver is included, in the form of the multiviews option in the sitecfg/siteini,php file.

sitecfg/siteini,php
[menu]
multiviews=1
will cause the menu system to automatically generate extensionless URLs for local files only. Offsite URLs will be unaffected.

When using the menu multiviews option, any menu reference to a local subdirectory rather than a local file must terminate in a /

In fact it is recommended that menu file entries always have the correct extension regardless of the multiviews setting, as you may later wish to move the site to a host which doesn't support multiviews. If you adhere to this practice, then all you need change is the multiviews option.

The provisos here are that you must not have a same-named subdirectory and page, as there would then be no way of telling whether a URL referred to the same-named page minus its extension, or to the default file (index.html) in the subdirectory Also it would not be wise to use this option if you have same-named php and html files in a directory. However these situations are fairly rare, and on most sites the multiviews option can be activated without issues arising.

Powered by Mara cms