开发者

Fatal Error when 2 Conditional Url Rewrite rules Fire simultaneously

Dear folks, Trying to rewrite images with a rewrite rule that should only fire when two conditions exist: image starts with IMG or better yet IMG- and secondly the file should exist.

Nice url: IMG-folder/file.jpg fetched ugly url ima开发者_Python百科ge under water.

The code below works when no conditions are set, as well as when only the second !-f condition is set, but not when both rules coexist. Why is this? Ideas/code/comments are very appreciated. Thanks

Q1. Im a bit confused: is the first condition actually necessary? Since I'm stating to only rewrite IMG-.... files to the ugly urls under water.

Q2. Why does this code below go wrong then both conditions are fired?

RewriteCond %{REQUEST_URI} ^IMG.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^IMG-(.+)_w(.+)_h(.+).jpg$ imgcpu\.php\?src=$1\.jpg&w=$2&h=$3 [L]


%{REQUEST_URI}, always contains the full requested path. The first argument of RewriteRule on the other hand is relative. If you match a %{REQUEST_URI} against a pattern that specifies the start position, ^, you should also include the leading slash.

RewriteCond %{REQUEST_URI} ^/IMG.*$

I'm also slightly confused about the form of the virtual URLs. Does IMG occur twice in a typical image URL? Is /IMG-folder/IMG-12_w34_h56.jpg a valid virtual filename?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜