1

With the assistance of htaccess, is it possible to have files stored as...

/content/001 Some sort of description.html
/content/002 Some sort of description.html

...or as...

/content/Some sort of description.001
/content/Some sort of description.002

...and get the desired file by requesting only the numeric portion of the name?

$.get("content/001", function(data) {
   • • • 
}, "html");

1 Answer 1

1

I don't think this is possible with the two examples you posted since there is no way to "search" for an arbitrary file based on a URL pattern AFAIK, without perhaps using a custom module.

However, if your files were named like the following instead, then it's possible to do this using MultiViews (mod_negotiation):

001.some-sort-of-description.html
002.another-description.html

Note the critical placement of the dots (.) to create file extension(s).

So, the number 001 is the file basename and some-sort-of-description and html are file extensions, then you can use MultiViews (mod_negotiation) to serve the appropriate file by requesting just the numeric portion of the filename.

It's important to end with a "known" file extension (like .html, .php or .txt etc.) that returns an appropriate mime-type. Simply naming the file 001.some-sort-of-description does not appear to be sufficient.

For this to work, you need to enable the broadest scope of MultiViews matching: Any. This potentially has security implications so only enable it on the specific directory that contains only your content files.

For example, in the /content/.htaccess file:

Options +MultiViews
MultiviewsMatch Any

Requesting just /content/001 or /content/002 should then serve the corresponding file. If there are two files with the same "number" then the smallest file is returned.

Reference:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.