2013-01-17 31 views
0

一個文件夾上的所有請求,還有很多類似的問題,但沒有提供的解決方案的適合我的需要。mod_rewrite的除了一個

我想轉發文件夾上的所有請求到一個特定的網址,除了一個請求應該被轉發到另一個網址。 這裏是我走到這一步:

RewriteCond %{REQUEST_URI} !^/test/test.html$<br /> 
RewriteRule .? http://www.example.com [L,NC,QSA] 

什麼現在缺少的是該請求/test/test.html應該被轉發到 www.example.com/test/index.html

我「M努力是爲了保護別人,除了該文件夾(測試)的任何請求都知道某個URL(測試/ test.html的),那麼它應該被轉發到測試/ index.html的

任何幫助,將不勝感激!

回答

0

我認爲這是你正在尋找

# internally redirect /test/test.html to /test/index.html 
RewriteRule ^test/test\.html$ /test/index.html [L] 
# don't do any more rewrites on the url: /test/index.html 
RewriteRule ^test/index\.html$ - [L] 
# internally redirect all (other) request to the root 
RewriteRule .*/[L] 
+0

感謝戈什麼,但在第一次調用仍然重定向到http://www.example.com。我想這是因爲在附加第一條規則之後,它會調用一個新的請求,並應用第二條規則!?有關於此的任何提示? – netcase

+0

由於'example.com'在重寫中,我認爲它是另一個主機,並且您想要重定向。請參閱上面的編輯 – Gerben

+0

對不起,這是同一個主機。奇怪的是,我被重定向到/test/test.html我使用的任何網址。看來[L]標誌沒有正確應用。 – netcase