2011-12-16 24 views
0

說我有以下頁面:htaccess重寫,在一個數組?

http://www.site.com/folder/page.php?id=89 
http://www.site.com/folder/page.php?id=85 
http://www.site.com/folder/page.php?id=camel+hump 
http://www.site.com/folder/page.php?id=76 
http://www.site.com/folder/page.php?id=71 
http://www.site.com/folder/page.php?id=frog 
http://www.site.com/folder/page.php?id=62 
http://www.site.com/folder/page.php?id=59 

,我想直接如下:

89,79,44,駱駝+駝峯以下網頁:

http://www.site.com/folder/page/$1 

EG :

http://www.site.com/folder/camel-hump (Notice the + replaced with a -) 

以及其他所有內容轉到下一頁:

http://www.site.com/folder/overview 

我該怎麼做?

基本上,我有大約200頁需要重定向,並且它們都與get參數有相同的URL,其中一些需要重定向到/folder/get-parameter頁面,其餘的需要重定向到/folder/overview頁面。

我還需要+標誌被替換 - 標誌,因此,例如camel+hump成爲camel-hump

我該怎麼做了重寫規則?喜歡的東西:

if match (89|79|44|camel+hump|frog) go to /folder/$1 (but replace + with -) 

一切,去/folder/overview

謝謝

回答

0

嘗試:

# Filter out the query string values for id that you want to rewrite 
RewriteCond %{QUERY_STRING} ^id=(89|79|44|camel\+hump|frog) 
RewriteRule ^folder/page.php$ /folder/page/%1? [L] 

# get rid of the + 
RewriteRule ^folder/page/(.+)\+(.+)$ /folder/page/$1-$2 [L] 
+0

出於某種原因+不被替換 - 符號,任何想法? – pdlol 2011-12-19 00:05:47