2011-09-24 37 views
0

我試圖做到這一點:
example.com/directory/song.mp3 - >不變
example.com/directory/ - > example.com/?dir=directory%2F
例子的.com/- >不變
example.com/index.php? - >不變

基本上,如果用戶請求根以外的任意目錄,我需要它改寫,不被重定向,到index.php DIR = <斜槓路徑已更改爲%2F> 我希望用戶仍然可以在其瀏覽器中看到example.com/path/to/stuff,但要重寫的請求是se rverside。mod_rewrite的目錄請求

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

我希望我清楚我所期待的。

回答

0

試試這個:

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

我只是測試這一點,它給了我一個內部服務器錯誤。我嘗試加載http://127.0.0.1/opentape/重寫規則不應該重寫,如果它? –

+0

我的錯誤。我添加了RewriteCond%{REQUEST_FILENAME} -d,因爲它正在重寫樣式表網址。唯一的問題是,它重寫爲index.php作爲相對路徑,導致404錯誤。 test.com/dir/被重寫爲test.com/dir/index.php?dir=/dir而不是test.com/index.php?dir=/dir。另外,有沒有辦法讓重定向服務器端?我希望test.com/dir/保留在瀏覽器窗口中。 –

+0

呃,這個問題搞砸了。它的工作有點。我將針對我現在遇到的問題開始一個新問題。謝謝。 –