在.htaccess中使用CDN的重定向时,重定向循环上的图像

编程入门 行业动态 更新时间:2024-10-09 15:15:33
本文介绍了在.htaccess中使用CDN的重定向时,重定向循环上的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个很难搞清楚什么是错的。

I am having a hard time figuring out what is wrong.

当我加入我的CDN的code到我的.htaccess重定向静态内容的CDN,它会导致对这些文件重定向循环。

As soon as I add my CDN's code to my .htaccess to redirect static content to the CDN, it results in a redirect loop on those files.

我注意到他们不断重定向到自己,而不是加载该文件。

I noticed they keep redirecting to themselves instead of loading the file.

我的.htaccess:

My .htaccess:

RewriteEngine On # Force no www RewriteCond %{HTTP_HOST} ^www [NC] RewriteRule ^.*$ domain/$0 [R=301,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ RewriteRule ^index\.php$ domain/ [R=301,L] # Rewrite domain/p/contact to index.php?p=contact RewriteRule ^p/([^/]+)/?$ /index.php?p=$1 [L]

我的CDN的code,打破了网站:

My CDN's code that breaks the site:

<IfModule mod_expires.c> ExpiresActive On ExpiresDefault A0 # Set up caching for 1 week(s) <FilesMatch "\.(jpe?g|gif|png|bmp|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav)$"> ExpiresDefault A604800 Header append Cache-Control "public" </FilesMatch> # Set up caching for 1 day(s) <FilesMatch "\.(xml|txt)$"> ExpiresDefault A86400 Header append Cache-Control "public" </FilesMatch> # Set up caching for 1 hour(s) <FilesMatch "\.(js|css)$"> ExpiresDefault A3600 Header append Cache-Control "proxy-revalidate" </FilesMatch> # Force no caching for dynamic files <FilesMatch ".(php|cgi|pl|htm)$"> ExpiresActive Off Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform" Header set Pragma "no-cache" </FilesMatch> </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP:Via} !\.s\.worldcdn\ # Flash wont work on cross-domain by default RewriteCond $1 !^.swf$ [NC] RewriteCond $1 "\.(jpe?g|gif|png|bmp|ico|js|css|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav|xml|txt)$" [NC] RewriteRule ^(.*) cdn.domain/$1 [L,R] </IfModule>

子站点,CDN等都是正确设置。

Subdomains, CDN etc. are all set up correctly.

也许这是与CDN的问题吗? 干杯您的帮助​​!

Maybe it's a problem with the CDN? Cheers for your help!

推荐答案

这标志→:阿帕奇文档:flag_l :

From Flag L: Apache Docs: flag_l :

如果您使用的是重写规则在任的.htaccess 文件或&LT;目录&GT; 部分,这一点很重要有怎样的规则处理一些了解。这样做的简化形式是,一旦规则已经被处理,则重写的请求被交还给URL解析引擎做它可以与它。这可能是因为所重写的请求的处理,.htaccess文件或部分可以再次遇到,因此规则集可再​​次从开始运行。无论是内部还是外部 - - 最常见的是如果一个规则导致重定向会出现这种情况,导致请求过程重新来过

If you are using RewriteRule in either .htaccess files or in <Directory> sections, it is important to have some understanding of how the rules are processed. The simplified form of this is that once the rules have been processed, the rewritten request is handed back to the URL parsing engine to do what it may with it. It is possible that as the rewritten request is handled, the .htaccess file or section may be encountered again, and thus the ruleset may be run again from the start. Most commonly this will happen if one of the rules causes a redirect - either internal or external - causing the request process to start over.

一直以来,重写的请求被传递回URL解析引擎,从最后一个重定向后重写规则这里,

Since, rewritten request is handed back to the URL parsing engine, after redirect from the last RewriteRule here,

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP:Via} !\.s\.worldcdn\ # Flash wont work on cross-domain by default RewriteCond $1 !^.swf$ [NC] RewriteCond $1 "\.(jpe?g|gif|png|bmp|ico|js|css|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav|xml|txt)$" [NC] RewriteRule ^(.*) cdn.domain/$1 [L,R] </IfModule>

无论是 编辑这一行:

either edit this line to :

RewriteRule ^(.*) cdn.domain/$1 [L]

如果你想拥有的URI的变化在浏览器为好,添加的第一个的RewriteCond

if you want to have the URI change at the browser as well, add the first RewriteCond

RewriteCond %{HTTP_HOST} !cdn\.domain\ RewriteCond %{HTTP:Via} !\.s\.worldcdn\ RewriteCond $1 !^.swf$ [NC] RewriteCond $1 "\.(jpe?g|gif|png|bmp|ico|js|css|pdf|docx?|xlsx?|ppt|rar|zip|tar|gz|tgz|bz2|flv|avi|mov|wmv|mp3|wav|xml|txt)$" [NC] RewriteRule ^(.*) cdn.domain/$1 [L,R]

更多推荐

在.htaccess中使用CDN的重定向时,重定向循环上的图像

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

发布评论

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

>www.elefans.com

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