CDN相关:重写图片来源的.htaccess自动网址

编程入门 行业动态 更新时间:2024-10-15 10:16:37
本文介绍了CDN相关:重写图片来源的.htaccess自动网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

最近我买了一个CDN,并设置它。在我的网站,影像储存在名为照片文件夹中的图片网址以这种方式显然是联系在一起的。 (*例如:图像/ some_image.png *)

Recently I bought a CDN and set it up. In my site, the images are stored in a folder named 'images' and the Image urls are obviously linked in this manner. (*Ex : images/some_image.png*)

由于我要使用CDN正确的方式,我需要重写的URL,而无需手动更改每个映像路径。

Since I want to use the CDN right way, I need to rewrite the urls without having to manually change each and every image path.

我试着一个.htaccess code这是提出了类似的问题。

I tried an .htaccess code which was suggested for a similar problem

RewriteEngine On RewriteBase / RewriteRule ^images/(.*)$ cdn.mydomain/$1 [L,R=301]

但是,这似乎并没有正常工作,因为所有的图像不正确链接。

But that didn't seem to work properly as all the images were linked improperly.

所以,我想知道的变化,这code。任何反应将是AP preciated。

So I would like to know the changes in this code. Any response would be appreciated.

推荐答案

这应该工作:

RewriteCond %{HTTP_HOST} ^yourdomain\$ [OR] RewriteCond %{HTTP_HOST} ^www\.yourdomain\$ RewriteRule ^images\/?(.*)$ "http\:\/\/cdn\.yourdomain\\/$1" [R=301,L]

不过,请注意,这只是一个治标不治本!为了获得最大出你的CDN,你需要手动为救一个HTTP,每一张图像指向CDN。

However, please note that this is just a temporary solution!In order to get the max out of your CDN, you need manually point images to your CDN in order to save one HTTP for every image.

更多推荐

CDN相关:重写图片来源的.htaccess自动网址

本文发布于:2023-11-02 00:17:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   来源   网址   图片   CDN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!