apache - Can mod_rewrite be used to find an older version of a file? -


say there 4 files on server contain dates in filename in way:

file_2014-01-20.txt file_2014-01-03.txt file_2014-01-02.txt file_2014-01-01.txt 

...and server receives request dated file doesn't exist:

file_2014-01-10.txt 

...is there way use mod_rewrite or other .htaccess code make find recent file older 1 requested? e.g. in case return file_2014-01-03.txt, since recent existing file older (nonexistent) requested file.

i know redirect 404's special script this:

rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.+) getarchive.php?request=$1 

...where getarchive.php take request , use find , return correct file. however, not solution me several reasons, , i'd redirecting entirely .htaccess without using server-side scripts @ if possible.

edit:

to put question way, given nonexistent filename, can apache used find next file in list, when sorted reverse-alphabetically.

example:

a.txt b.txt z.txt 

given request n.txt, server returns b.txt.

you're going way better off writing script this. date comparison using mod_rewrite, if manages it, sounds horrible idea. how going code previous years? (like file_2013-12-30.txt , file_2014-01-30.txt)

the functionality of mod_rewrite inadequate kind of comparison.

you'll have create groupings year, month , date, comparisons them without use of conditionals (there's no if/then/else in mod_rewrite, have enumerate every possible condition every time every rule) or controlled loops, without arithmetic functions, , without means find file next lowest number date, or date/month, or date/month/year. means request file_2014-01-10.txt have check if file file_2014-01-09.txt exists, if file_2014-01-08.txt exists, if file_2014-01-07.txt exists, etc. without being able math.

not saying isn't possible create clever way make work somehow, god whoever has make tweak afterwards.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -