htAccess 重写对图像不起作用


htaccess rewrite not working for images

接受任何人都可以提供的任何帮助,

有一个旧的 url 结构:产品/类别(类别是动态的,仅用作示例),我正在尝试更改为类别/产品,为此我使用了

RewriteRule ^(.*)/products index.php?category=$1

这是有效的,但是问题是我的图像存储为图像/产品/图像,并且规则正在写入我的所有图像链接,

我试过:

RewriteRule ^images/products/(.*) images/products/$1

只是为了重写图像,但它没有接缝工作

我的htAccess文件如下所示:

RewriteRule ^images/products/(.*) images/products/$1
RewriteRule ^(.*)/products index.php?category=$1

提前感谢,

最简单的方法是添加一个规则,不重写现有目录和文件(您的图像...)的任何路径。

为此,可以在重写规则之前添加以下规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/products index.php?category=$1

> Jeroen 的答案也有效,但您也可以指定规则作为终点

RewriteRule ^images/products/(.*) images/products/$1 [L]
RewriteRule ^(.*)/products index.php?category=$1

"[L]"应防止解析第二条规则,因为第一条规则应按预期工作。