【问题标题】:Rewrite Image URL重写图像 URL
【发布时间】:2013-12-16 12:33:07
【问题描述】:
【问题讨论】:
标签:
php
image
.htaccess
caching
url-rewriting
【解决方案1】:
如果 url 在同一台服务器上,您可以使用内部重写。如果您转到http://example.com/mygraph.png,它将在内部重写到该文件路径,并且客户端仍会在其网址栏中看到http://example.com/mygraph.png。
RewriteRule ^mygraph.png$ /chart.png?type=graph&graphid=&width=840&height=300&id=9776&username=myuser&passhash=mypasshash [L]
如果图像位于外部域中,您必须代理请求。当请求http://example.com/mygraph.png 时,您的服务器将通过内部代理重做对外部服务器的请求。因此,外部服务器会将您视为线路的另一端,而您的服务器会将外部服务器的响应传递给客户端。
RewriteRule ^mygraph.png$ http://externaldomain.com/chart.png?type=graph&graphid=&width=840&height=300&id=9776&username=myuser&passhash=mypasshash [P,L]
mod_rewrite 的文档可以在here 找到。 This documentation 提供有关代理的更多信息。