gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:59:23 25 4
gpt4 key购买 nike

我很难弄清楚出了什么问题。

一旦我将我的 CDN 代码添加到我的 .htaccess 以将静态内容重定向到 CDN,它就会导致这些文件的重定向循环。

我注意到他们一直重定向到自己而不是加载文件。

我的.htaccess:

RewriteEngine On

# Force no www
RewriteCond %{HTTP_HOST} ^www [NC]
RewriteRule ^.*$ http://domain.com/$0 [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://domain.com/ [R=301,L]

# Rewrite domain.com/p/contact to index.php?p=contact
RewriteRule ^p/([^/]+)/?$ /index.php?p=$1 [L]

我的 CDN 破坏站点的代码:
<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\.com
# 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 ^(.*) http://cdn.domain.com/$1 [L,R]
</IfModule>

子域、CDN 等都设置正确。

可能是CDN的问题?
为您的帮助干杯!

最佳答案

来自旗帜 L :Apache Docs: flag_l :

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.



因为,在从最后一个 RewriteRule 重定向之后,重写的请求被传递回 URL 解析引擎。这里,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:Via} !\.s\.worldcdn\.com
# 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 ^(.*) http://cdn.domain.com/$1 [L,R]
</IfModule>

任何一个
将此行编辑为:
    RewriteRule ^(.*)           http://cdn.domain.com/$1 [L]

或者,

如果您还想在浏览器中更改 URI,请添加第一个 RewriteCond
    RewriteCond %{HTTP_HOST}  !cdn\.domain\.com
RewriteCond %{HTTP:Via} !\.s\.worldcdn\.com
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 ^(.*) http://cdn.domain.com/$1 [L,R]

关于.htaccess - 在 .htaccess 中使用 CDN 重定向时在图像上重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9112773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com