首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用.htaccess将图像重定向到php脚本

用.htaccess将图像重定向到php脚本
EN

Stack Overflow用户
提问于 2017-12-06 09:14:54
回答 1查看 1.2K关注 0票数 2

我正在尝试将自适应图像- http://www.adaptive-images.com/整合到我的网站中。

Github帐户- https://github.com/MattWilcox/Adaptive-Images

理想情况下,.htaccess应该将所有图像重定向到AdaptiveImages.php,并调整输出图像的大小。

图像没有载入。我检查了响应头及其返回的文本/html。似乎请求将转到index.php文件。

下面是我正在使用的当前.htaccess

代码语言:javascript
运行
复制
<IfModule mod_rewrite.c>

  RewriteEngine On

  # Send any GIF, JPG, or PNG request that IS NOT stored inside ai-cache
  # to adaptive-images.php

  RewriteCond %{REQUEST_URI} !/ai-cache
  RewriteRule \.(jpe?g|gif|png)$ adaptive-images.php

  # Send all files except css, js or image files to index.php

  RewriteBase /
  RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
  RewriteRule ^.*$ index.php

</IfModule>

第一部分是我试图让它发挥作用的地方

第二部分工作得很好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-06 09:20:12

您可以使用表示原始REQUEST_URI请求的THE_REQUEST来更改REQUEST_URI,并且在应用其他规则之后不会改变,这与REQUEST_URI不同。

代码语言:javascript
运行
复制
DirectoryIndex index.php

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /

  # Send any GIF, JPG, or PNG request that IS NOT stored inside ai-cache
  # to adaptive-images.php

  RewriteCond %{REQUEST_URI} !/ai-cache [NC]
  RewriteRule \.(jpe?g|gif|png)$ adaptive-images.php [L]

  # Send all files except css, js or image files to index.php

  RewriteCond %{THE_REQUEST} !(robots\.txt|\.(css|js|png|jpe?g|gif)) [NC]
  RewriteRule . index.php [L]

</IfModule>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47670596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档