.htaccess - 如何覆盖 .htaccess 文件 Apache2 中的文件请求?
问题描述
# Structure
- example.com/static
-- .htaccess
-- images
--- file.png
--- file_cache.png
-- photos
--- file.jpg
--- file_cache.jpg
我想重写这条规则 GET param from URI 并返回文件。
例如:
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
谢谢!
解决方案
You can create a new file static/images/.htaccess
and use this rule:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^type=([^&]+)$
RewriteRule ^file\.(png|jpe?g)$ file_%1.$1? [L,NC]
推荐阅读
- python - 如何在 keras 中创建过采样(在 caffe lib 中相同)
- java - 如何在 Glide 中获得不超过一定大小的缩略图?
- r - R通过组合两个变量的共同值来重塑数据
- python - 在python函数中如何传递一个可选参数进行过滤
- java - 关于如何创建守护线程来监控地图的最佳实践
- vba - 错误 1004 宏 Excel
- ms-access - 密码保护表单访问
- html - 将光标设置为元素的默认样式或元素:悬停?
- windows - 安装 choco 后,gitlab-ci 在 refreshenv 后退出作业
- javascript - jquery UI 滑块,更改事件显示 *递归过多*