【问题标题】:How override request to file in .htaccess file Apache2?如何覆盖 .htaccess 文件 Apache2 中的文件请求?
【发布时间】:2020-01-28 20:53:09
【问题描述】:
# Structure
- example.com/static
-- .htaccess
-- images
--- file.png
--- file_cache.png
-- photos
--- file.jpg
--- file_cache.jpg

我想重写这条规则 GET param from URI and return file.

例如:

http://example.com/static/images/file.png

(- 服务器将尝试通过链接返回文件)

但是!

当用户声明 GET 参数和值等于“type=cache”时。

然后通过链接

http://example.com/static/images/file.png?type=cache

服务器返回文件

http://example.com/static/images/file_cache.png

谢谢!

【问题讨论】:

    标签: .htaccess apache2


    【解决方案1】:

    您可以创建一个新文件static/images/.htaccess 并使用此规则:

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^type=([^&]+)$
    RewriteRule ^file\.(png|jpe?g)$ file_%1.$1? [L,NC]
    

    【讨论】:

    • 您能在这里提供详细信息吗?使用此规则,您使用了什么 url 以及遇到了什么错误
    • @Nick:“这对我不起作用”不是一个很有帮助的报告。您看到了哪些意外行为?
    猜你喜欢
    • 2014-08-22
    • 2021-09-21
    • 2016-10-29
    • 2013-10-14
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多