htaccess: redirects the root to the current year subdirectory if it exists, otherwise to a previous year that does exist

Using mod_rewrite in .htaccess It is relatively simple to redirect to the "current year" if that year exists as a physical directory in the file system.

For example, you can do something like the following at the top of the .htaccess File in the root of the document:

RewriteEngine On

RewriteCond% {DOCUMENT_ROOT} /% {TIME_YEAR} -d
RewriteRule ^ $ /% {TIME_YEAR} / [R=302,L]

You do not need to repeat the RewriteEngine Directive if it is already present in the file.

Note that this is a temporary redirect (302), so the redirect is retrieved when the "current year" changes.

Issue… redirecting to a "previous year" is not as trivial as you can not perform basic arithmetic on .htaccess only say subtract 1 year For this I would need server-side access to create a RewriteMap That calls an external function. Or rewrite a script (PHP) that can determine the correct year to redirect to.

However, this is probably related to your other question in the WordPress stack. In which case there is a physical directory For the years 2013 onwards?