301重定向/所有影像复制到CDN重定向、影像、CDN

2023-09-02 00:44:43 作者:从别后,忆相逢

对于图像库我必须使用CDN。为此我创建了一个子域

  image.example.com
 

通过CNAME此子域名指向CDN URL。

旧图像路径:

  http://www.example.com/files/thumbs
 

我改变了画廊的所有图像路径:

  http://images.example.com/files/thumbs
 
战网下载CDN重定向工具下载 战网下载CDN重定向v1.0 免费版 腾牛下载

我需要从

301重定向

  http://www.example.com/files/thumbs
 

  http://images.example.com/files/thumbs
 

我已经作了一个关于这个职位。

Redirect文件夹,子站点文件夹

在与anubhava协调,我现在打开一个新的问题。

我尝试这样做:

 的RewriteCond%{HTTP_HOST} ^(?:WWW )?例如 .COM $ [NC]
重写规则^(文/大拇指/.*)$ http://images.example.com/$1 [L,R = 301,NC]
 

和这样的:

 重写规则^(文/大拇指/.*)$ http://images.example.com/$1 [L,R = 301,NC]
 

这两个规则导致。重定向过多/永不落幕

重要提示:

在CDN缓存了图像,一切正常,因为它应该。在CDN需要2请求和第三个要求是一个打击。当CDN没有命中(第一或第二的请求)重定向无法正常工作。 当在CDN错过文件,本地服务器SERV图像。有没有适合我的需要的规则?

非常感谢你。

-----有关问题的补充更多的信息----

我们有2个场景 - 碰运气:

情景1 - 命中

请查看下面的步骤,对上面的X-缓存中的眼睛和HTTP状态code:

  1。卷曲-I http://images.example.com/files/thumbs/my-cache-hitting-image.jpg

HTTP / 1.1 200 OK
日期:周五,2015年3月27日7点37分10秒格林尼治标准​​时间
内容类型:图像/ JPEG
内容长度:14525
连接:保持活动
最后一次修改:周四,2015年3月19日12点44分39秒格林尼治标准​​时间
缓存控制:最大年龄= 2592000
到期日:太阳,2015年4月26日7时37分10秒格林尼治标准​​时间
变化:用户代理
服务器:NetDNA缓存/ 2.2
的X缓存:HIT
接受-范围:字节
 

现在我们检查行动中的重定向(开旧的URL):

 卷曲-I http://www.example.com/files/thumbs/my-cache-hitting-image.jpg

HTTP / 1.1 301永久移动
日期:周五,2015年3月27日7时三十九分06秒格林尼治标准​​时间
服务器:Apache
地点:http://images.example.com/files/thumbs/my-cache-hitting-image.jpg
有所不同:接受编码
内容类型:text / html的;字符集= ISO-8859-1
 

完美! - 作业已完成

情景2 - 小姐

 卷曲-I http://images.example.com/files/thumbs/my-cache-missing-image.jpg

HTTP / 1.1 301永久移动
日期:周五,2015年3月27日7时41分27秒格林尼治标准​​时间
内容类型:text / html的;字符集= ISO-8859-1
内容长度:278
连接:保持活动
地点:http://images.example.com/files/thumbs/my-cache-missing-image.jpg
有所不同:接受编码
服务器:NetDNA缓存/ 2.2
到期日:太阳,2015年4月26日七点41分27秒格林尼治标准​​时间
缓存控制:最大年龄= 2592000
的X缓存:MISS
 

Fazit:当有一个MISS,它会导致在循环中,因为在CDN给出请求回原点和原点是这样做的:

 卷曲-I http://www.example.com/files/thumbs/my-cache-missing-image.jpg

HTTP / 1.1 301永久移动
日期:周五,2015年3月27日7时26分13秒格林尼治标准​​时间
服务器:Apache
地点:http://images.example.com/files/thumbs/my-cache-missing-image.jpg
有所不同:接受编码
内容类型:text / html的;字符集= ISO-8859-1
 

它是一个循环,永远不会结束。也许有一种方法,通过httaccess电导率检查状态code?!

解决方案

我发现了一个workarround。也许有人会需要它:

当我想从旧(索引)URL重定向到CDN URL和CDN还给源URL,这也是旧的URL,其​​运行过程中进入循环。

解决方案:创建一个不同的URL,其​​中CDN可以捕捉文件。因此,请执行以下操作:

  

创建一个子域 - 例如:

  catcher.example.com(普通A记录)
 

  

指向该子到网站根目录下。具有相同目录作为原始网站的目录。

     

添加catcher.example.com到您的CDN设置的源URL。

     

添加一个重写COND,这将迫使重定向时,才会有旧的URL,而不是从我们的catcher.example.com

 的RewriteCond%{REQUEST_URI} ^ /文件/大拇指
的RewriteCond%{HTTP_HOST} ^ www.example.com $
重写规则^(文/大拇指/.*)$ http://images.example.com/$1 [L,R = 301,NC]
 

(我需要第一的RewriteCond?)以防万一,我已经加入。

结果:无环了。因为这样的CDN可以捕获从catcher.example.com文件和旧链接获得重定向到Apache无果在一个循环。它doestn无论从哪里CDN可以用相同的目录路径赶上文件,只要它的同一个文件。

首先测试是全成。如果我错了,请大家指正。

For a image gallery I have to use a CDN. Therefor I create a subdomain

image.example.com

This subdomain points via CNAME to the CDN URL.

Old image path:

http://www.example.com/files/thumbs

I changed all image path in the gallery to:

http://images.example.com/files/thumbs

I need a 301 redirect from

http://www.example.com/files/thumbs

to

http://images.example.com/files/thumbs

I made already a post about this.

Redirect folder to subdomain with folder

In coordination with anubhava I open now a new question.

I tried this:

RewriteCond %{HTTP_HOST} ^(?:www.)?example.com$ [NC]
RewriteRule ^(files/thumbs/.*)$ http://images.example.com/$1 [L,R=301,NC]

and this:

RewriteRule ^(files/thumbs/.*)$ http://images.example.com/$1 [L,R=301,NC]

Both rules result in: Too many redirects / never ending.

Important:

When the CDN has cached the image, everything works as it should. The CDN need 2 request and the 3rd request is a hit. When the CDN has no hit (first or second request) the redirection is not working. When the CDN miss the file, the local server serv the image. Is there a rule that fits my needs?

thank you very much

-----Added more informations about the problem----

We have 2 scenarios - HIT and MISS:

Scenario 1 - The HIT

Please check the following steps and have a eye on the X-Cache and the http Status Code on top:

1. curl -I http://images.example.com/files/thumbs/my-cache-hitting-image.jpg

HTTP/1.1 200 OK
Date: Fri, 27 Mar 2015 07:37:10 GMT
Content-Type: image/jpeg
Content-Length: 14525
Connection: keep-alive
Last-Modified: Thu, 19 Mar 2015 12:44:39 GMT
Cache-Control: max-age=2592000
Expires: Sun, 26 Apr 2015 07:37:10 GMT
Vary: User-Agent
Server: NetDNA-cache/2.2
X-Cache: HIT
Accept-Ranges: bytes

Now we check the redirect in action (open old url):

curl -I http://www.example.com/files/thumbs/my-cache-hitting-image.jpg

HTTP/1.1 301 Moved Permanently
Date: Fri, 27 Mar 2015 07:39:06 GMT
Server: Apache
Location: http://images.example.com/files/thumbs/my-cache-hitting-image.jpg
Vary: Accept-Encoding
Content-Type: text/html; charset=iso-8859-1

Perfect - Job done!

Scenario 2 - The Miss

curl -I http://images.example.com/files/thumbs/my-cache-missing-image.jpg

HTTP/1.1 301 Moved Permanently
Date: Fri, 27 Mar 2015 07:41:27 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 278
Connection: keep-alive
Location: http://images.example.com/files/thumbs/my-cache-missing-image.jpg
Vary: Accept-Encoding
Server: NetDNA-cache/2.2
Expires: Sun, 26 Apr 2015 07:41:27 GMT
Cache-Control: max-age=2592000
X-Cache: MISS

Fazit: When there is a MISS, it will result in a Loop because the CDN gives the request back to the origin and the origin is doing this:

curl -I http://www.example.com/files/thumbs/my-cache-missing-image.jpg

HTTP/1.1 301 Moved Permanently
Date: Fri, 27 Mar 2015 07:26:13 GMT
Server: Apache
Location: http://images.example.com/files/thumbs/my-cache-missing-image.jpg
Vary: Accept-Encoding
Content-Type: text/html; charset=iso-8859-1

Its a loop that never ends. Maybe there is a way to check via httaccess Cond the status Code?!

解决方案

I found a workarround. Maybe anybody will need it:

When I want a redirect from old (indexed) url to cdn url and cdn give it back to origin url that is also the old url, its runs of course into a loop.

Solution: Create a different URL where the CDN can catch the files. Therefore do the following:

Create a subdomain - Example:

catcher.example.com (normal A record)

Point this subdomain to your root directory of the website. Has to be the same directory as the original website directory.

Add catcher.example.com to the origin URL in your CDN Settings.

Add a rewrite cond that will force the redirect ONLY when there is OLD url and NOT from our catcher.example.com

RewriteCond %{REQUEST_URI} ^/files/thumbs  
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(files/thumbs/.*)$ http://images.example.com/$1 [L,R=301,NC]

(do I need the first RewriteCond?) Just in case I have added.

Result: No loop anymore. Because that way the CDN can catch the files from the catcher.example.com and the OLD links getting a redirect to the apache without result in a loop. It doestn matter from where the CDN can catch the file as long its the same file with the same directory path.

First tests are successfull. When I am wrong, please correct me.