开发者

How to use multiple RewriteRule rules in htaccess?

I'm using 2 RewriteRule rules in my htaccess

RewriteEngine on
RewriteBase /
# if a directory o开发者_StackOverflow中文版r a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#if it has member/photo/render_fast forward to photo_render.php
RewriteRule ^member/photo/render_fast(.*) /photo_render.php?r=$1 [L]
# otherwise forward it to index.php
RewriteRule . index.php [L]

However this doesn't work, when I'm trying in my local machine, my Apache always use the second rule, and in my hosting server Apache always display an error.

What am I doing wrong ?


What's happening is the 2nd time around (after the URI has been rewritten to /photo_render.php) the 2nd rule is being applied, thus /photo_render.php is getting rewritten to index.php. You need to add a few conditions when you try to match something like . or .*. This should work:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^member/photo/render_fast(.*) /photo_render.php?r=$1 [L]
# otherwise forward it to index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Note that this will also fail if for some reason you don't have photo_render.php.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜