gpt4 book ai didi

apache - htaccess - 条件重写和过期

转载 作者:行者123 更新时间:2023-12-04 18:48:19 25 4
gpt4 key购买 nike

嘿!

我有一个文件夹 /static在我的 Apache 2.x 服务器 webroot 中。如果请求匹配

/static/<somename like [\S-_]+>.(png|jpg|css|js)/\d{8,15}

例如
/static/bg.jpg/1335455634

我想要两件事:
  • url 应改写为 /static/bg.jpg (去掉时间戳)
  • 它将变成 never-expire ('expires 2030, max-age=290304000, public cache, ...)

  • 如果请求不匹配,请求及其 header 应该是正常的,没有重写。理想情况下,/static/* 之外的任何请求都不应受到影响(尽管“巧合的尾随时间戳”应该很少见......)

    我只有 FilesMatch/RewriteCond 的问题,所以我宁愿不发布我糟糕的尝试......(在我的机器上启用了通用重写,我确实拥有发送缓存相关 header 的权利)

    丹克申!

    最佳答案

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /

    RewriteRule ^static/([^.]+\.(png|jpe?g|css|js))/\d{8,15}$ static/$1 [L,R,NC]

    # now set expire date to today + 1 year
    <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType image/jpeg "access plus 1 years"
    ExpiresByType image/png "access plus 1 years"
    ExpiresByType text/css "access plus 1 years"
    ExpiresByType text/js "access plus 1 years"
    ExpiresByType text/javascript "access plus 1 years"
    ExpiresByType application/javascript "access plus 1 years"
    ExpiresByType application/x-javascript "access plus 1 years"
    </IfModule>
    我选择了 iccess plus 1 years永不过期 因为我在网上找到了这个:

    "To mark a response as "never expires," an origin server sends anExpires date approximately one year from the time the response issent. HTTP/1.1 servers SHOULD NOT send Expires dates more than oneyear in the future."

    From the HTTP 1.1 RFC

    关于apache - htaccess - 条件重写和过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10336132/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com