I think you probably have a conflict with mod_dir (and the
DiretcoryIndex). Although I'm surprised this "works perfectly in
.htaccess" (unless you have something else that prevents a loop)?
If you rewrite to the bare directory, ie.
/dir/ then mod_dir will trigger an internal subrequest to
/dir/index.php (or whatever your
DirectoryIndex is set to) and this will likely trigger an endless loop (despite your
END flag) since
You should be rewriting directly to the index document and this should solve the problem. For example:
RewriteRule !^/?dir/$ /dir/index.php [END]
You don't need the
RewriteCond directive that checks against
REQUEST_URI, you can do the same check in the
RewriteRule pattern - which is marginally more efficient and saves you a directive.