.htaccess Mod_重写目录请求

.htaccess Mod_重写目录请求,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我正在尝试这样做: example.com/directory/song.mp3->未更改 example.com/directory/->example.com/?dir=目录%2F example.com/->未更改 example.com/index.php->未更改 基本上,如果用户请求根目录以外的任何目录,我需要将其重写,而不是重定向到index.php?dir= 我希望用户仍能在浏览器中看到example.com/path/to/stuff,但请求在服务器端被重写 example.c

我正在尝试这样做: example.com/directory/song.mp3->未更改 example.com/directory/->example.com/?dir=目录%2F example.com/->未更改 example.com/index.php->未更改 基本上,如果用户请求根目录以外的任何目录,我需要将其重写,而不是重定向到index.php?dir= 我希望用户仍能在浏览器中看到example.com/path/to/stuff,但请求在服务器端被重写

example.com/songs/stuff->example.com/?dir=songs%2fsuff

我希望我清楚我在寻找什么。

试试这个:

RewriteRule ([^/]+/.*) /index.php?dir=$1

我刚刚测试了这个,它给了我一个内部服务器错误。我尝试加载重写规则不应该重写,应该吗?我的错误。我添加了RewriteCond%{REQUEST_FILENAME}-d,因为它正在重写样式表url。唯一的问题是,它作为相对路径重写为index.php,导致404个错误。test.com/dir/被重写为test.com/dir/index.php?dir=/dir,而不是test.com/index.php?dir=/dir。还有,有没有一种方法可以使服务器端重定向?我希望test.com/dir/保持在浏览器窗口中。唔,这个问题搞砸了。它有点起作用了。对于我现在遇到的问题,我将开始一个新问题。谢谢