只有文件夹不存在时,RewriteRule才起作用

我不需要直接访问图像,而需要使用RewriteRule来redirect一组要通过脚本访问的图像。

RewriteRule用于它:

RewriteRule ^Images/test/([^.\/]*)\.png /image.php?file=$1.png [R=301,L] 

我希望这会改变:

www.example.com/ 图片 /test/123.png

www.example.com/image.php?file=123.png

但它不这样做。

但是,如果我将RewriteRule更改为以下内容:

 RewriteRule ^Images2/test/([^.\/]*)\.png /image.php?file=$1.png [R=301,L] 

以下工作:

www.example.com/ Images2 /test/123.png

www.example.com/image.php?file=123.png

不同之处在于Images存在而Images2不存在。 是否有可能使用现有的文件夹。

任何帮助如何获得顶部的例子工作?

更新 :仔细查看mod_rewrite文档后 ,我发现:

…请注意,mod_rewrite会尝试通过检查path的第一部分是否存在于文件系统的根目录来尝试猜测您是否指定了文件系统path或URLpath。

看起来,如果path被解释为一个URLpath,它将起作用,如果它被解释为一个文件系统path,它就会失败。

试试这个

 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$0 [L] 

运气!!

尝试改变你的锚的开始^/ ,只是一个预感。 我还没有亲自使用RewriteRules锚定在行的开始,不是以斜杠开头,但我可以看到如何在引擎内创build一些怪异的东西。