2013-02-11 52 views
0

我想用RedirectMatch指令的形式重新創建mod_rewrite規則。RedirectMatch用於重新編排目錄結構的Mod_Rewrite規則

首先,請大家一起來看看這款的mod_rewrite規則:

RewriteEngine On 
RewriteCond %{HTTP_HOST} (www.)?africananimals.com 
RewriteCond %{REQUEST_URI} zebras 
RewriteRule ^(stripes|hooves)/zebras/?$ zebras/$1 [R,L] 

規則(由一個非常有益的和有知識的StackOverflow貢獻者書面)告訴服務器改造這四個網址:

http://africananimals.com/stripes/zebras

http://africananimals.com/hooves/zebras

http://www.africananimals.com/stripes/zebras

http://www.africananimals.com/hooves/zebras

- 到這些更好,更邏輯結構的:

http://africananimals.com/zebras/stripes

http://africananimals.com/zebras/hooves

http://www.africananimals.com/zebras/stripes

http://www.africananimals.com/zebras/hooves

(這些不是實際的URL,只是例子。)

該託管服務器上還有其他網站,它可能碰巧具有相同的目錄結構,所以第一個條件確保規則僅適用於africananimals.com域名,有或沒有www。

第二個條件確保規則僅適用於URL中存在單詞「斑馬」的情況。

規則本身選擇「stripes」或「hooves」後跟「/ zebras」或「/ zebras /」並重寫URL,將之前選擇的項目(「條紋」或「蹄子」)放在「斑馬/「 - 就像它應該做的一樣。

問題:怎麼能同一個任務使用RedirectMatch指令來完成?

作爲一名Apache業餘愛好者,我非常感謝專業人士的洞察力。

+1

我想這樣的事情會做到這一點:?'RedirectMatch 301^/(條紋|蹄)/斑馬/ $ http://africananimals.com /斑馬/ $ 1' – 2013-02-11 03:03:48

+0

謝謝@faa,那正是我需要的!您是否想將其作爲實際答案輸入,以便我可以將其選爲最佳答案? – 2013-02-11 03:15:11

+0

好的。謝謝。我會做出答案。 – 2013-02-11 03:16:01

回答

1

我想這樣的事情會做到這一點:

RedirectMatch 301 ^/(stripes|hooves)/zebras/?$ http://africananimals.com/zebras/$1