[英]Redirect to a single URL based on the date stated in other URLs
我正在尝试这样做,
使用单个 URL 根据日期显示不同的图像。 例如, https://example.com/imageoftheday/
我已经上传了一系列图片。 他们的 URL 类似于https://example.com/images/2022/01/22/image.jpg
和https://example.com/images/2022/01/23/image.jpg
I wish that on the day, say Jan 22, https://example.com/images/2022/01/22/image.jpg
will appear at https://example.com/imageoftheday/
and if it's Jan 23, https://example.com/images/2022/01/23/image.jpg
将会出现。
那可能吗?
如果您想使用 Apache/ .htaccess
,那么有各种TIME_XXXXX
服务器变量可用于当前日期和时间信息,因此您可以使用 mod_rewrite 执行以下操作,无条件地将/imageoftheday/
的请求重写为当前/images/<year>/<month>/<day>/image.jpg
/<月>/ /images/<year>/<month>/<day>/image.jpg
:
RewriteEngine On
RewriteRule ^imageoftheday/$ images/%{TIME_YEAR}/%{TIME_MON}/%{TIME_DAY}/image.jpg [L]
如果您想在重写之前先测试图像是否存在并在不存在时显示default.jpg
图像,那么您可以这样做:
RewriteCond %{DOCUMENT_ROOT}/images/%{TIME_YEAR}/%{TIME_MON}/%{TIME_DAY}/image.jpg -f
RewriteRule ^imageoftheday/$ images/%{TIME_YEAR}/%{TIME_MON}/%{TIME_DAY}/image.jpg [L]
RewriteRule ^imageoftheday/$ images/default.jpg [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.