Apache:mod-rewrite 在另一个目录中查找丢失的图像

cla*_*amp 1 mod-rewrite apache-2.2

我是 Apache mod 重写的新手。我想达到的就是这个。

如果从 url 请求图像 (gif, jpg, png) 并且在那里找不到,它应该自动尝试从另一个目录传递此图像。

Sha*_*den 5

尝试这个:

RewriteEngine on
# if there's no file at the requested path..
RewriteCond %{REQUEST_FILENAME} !-f
# then, if it's an image file, try the other path:
RewriteRule /([^/]*\.(gif|png|jpg))$ /images/path/$1
Run Code Online (Sandbox Code Playgroud)

这将作用于应用这些规则的每个图像文件请求;仅限于特定的“原始”目录,然后根据需要进行调整:

RewriteRule ^/old/images/path/([^/]*\.(gif|png|jpg))$ /images/path/$1
Run Code Online (Sandbox Code Playgroud)

如果您将其放入.htaccess或更改RewriteBase,请相应更改。