如何通过 mod_rewrite 替换转义的斜杠?

How to replace escaped slashes via mod_rewrite?

我正在将带有奇怪 php 目录浏览脚本的旧 Web 服务器迁移到具有标准目录浏览功能的 apache httpd 服务器。 旧脚本需要 url 个 http://myserver/index.php?fm_dir=dir1%2Fsubdir1%2Fsubdir2 现在应该用 url 代替 http://myserver/dir1/subdir1/subdir2

为了轻松迁移,我尝试通过 mod 重写来重写 url。

我已经尝试过以下方法:

RewriteCond %{QUERY_STRING} ^fm\_dir\=(.*)$
RewriteRule index\.php$ /%1? [R]

但是转义的斜杠仍然被转义,我得到了 404 (http://myserver/dir1%2Fsubdir1%2Fsubdir2)。

谁能告诉我如何解决这个问题。

RewriteCond %{QUERY_STRING} ^fm\_dir\=(.*)$
RewriteRule index\.php$ /%1? [NE,N]

# as long as there are two or more slashes, 
# replace only one and keep looping internally
RewriteRule ^(.*)\%2F(.*)\%2F(.*) /\%2F [NE,N]

# when there is only one left, 
# replace that last one and send redirect to the client
RewriteRule ^(.*)\%2F(.*) / [L,R=302]