gpt4 book ai didi

.htaccess - 自适应图像 CakePHP htaccess

转载 作者:行者123 更新时间:2023-12-02 14:33:11 25 4
gpt4 key购买 nike

我正在尝试让 Matt Wilcox 自适应图像与 CakePHP 一起使用,但没有成功。 http://adaptive-images.com/

CakePHP 附带了它自己的三个 .htaccess 文件。在 / 中,一个在 /app/ 中,一个在 /app/webroot/

我需要让这四个文件协同工作,以便将图像请求发送到我放在根目录中的文件adaptive-images.php。

这是来自自适应图像的htaccess

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

# Adaptive-Images -----------------------------------------------------------------------------------

# Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
# RewriteCond %{REQUEST_URI} !some-directory
# RewriteCond %{REQUEST_URI} !another-directory

RewriteCond %{REQUEST_URI} !assets

# Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
# to adaptive-images.php so we can select appropriately sized versions
RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

# END Adaptive-Images -------------------------------------------------------------------------------
</IfModule>

这是来自root的蛋糕htaccess/

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

这是来自/app/的蛋糕 htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>

这是来自/app/webroot 的蛋糕 htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

我假设自适应图像的规则必须出现在其中一个文件中的第一个,并且可能会为最后一个规则或其他内容添加一个 [L]。但到目前为止,我唯一能完成的就是打破图像 /img/myimage.gif 的路径,以便 Cake 开始寻找 ImgController。

Apache 日志没有给我任何有值(value)的东西。

有什么建议吗?

编辑:目前看起来像这样

我修改后的 / - htaccess 现在如下所示。 Cake 给我一个关于缺少 ImgController 的错误,并且在自适应图像应该放入的 ai-cache-folder 中没有创建图像。

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !assets
RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

RewriteCond %{REQUEST_URI} !adaptive-images\.php [NC]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

最佳答案

好吧,即使它可能不是最好的解决方案,我也能正常工作。

我只更改了 /app/webroot 文件夹中的 htaccess,如下所示

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !debug_kit
RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

并将adaptive-images.php 文件添加到app/webroot 将adaptive-images.php 文件放在Vendor 目录中可能会更好,但至少它可以工作。

我在adaptive-images.php中做了两处更改

$cache_path    = "app/tmp/cache/ai-cache";
$source_file = $document_root.'/app/webroot'.$requested_uri;

关于.htaccess - 自适应图像 CakePHP htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15105877/

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