2012-10-15 52 views
1

我在Windows 2003服務器上的IIS6上使用iirf。我們有以下的代碼來呈現乾淨的URL,並刪除任何查詢字符串:在剝離查詢字符串後重寫條件不起作用

RewriteRule ^/(.+)\?(.+)&(.+)\.(htm)$ /$1  
RewriteRule ^/(.+)\?(.+)$  http://betatest.bracknell-forest.gov.uk/$1 [R=301] 

# Redirect to ASP if it exists. 
# e.g. example.com/foo will display the contents of example.com/foo.asp 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.asp -f 
RewriteRule ^(.+)$ $1.asp [L,QSA] 
RedirectRule ^/(.+)\.(asp)$  http://betatest.bracknell-forest.gov.uk/$1 [R=301] 

# Any bare URL will get rewritten to a URL with .htm appended 
RewriteRule ^/([\w]+)$ /$1.htm [I,L] 
RedirectRule ^/(.+)\.(htm)$  http://betatest.bracknell-forest.gov.uk/$1 [R=301] 

的問題是,因爲我已經添加 重寫規則^/\(+)。&(+)(+)? (HTM)/ $ 1
重寫規則^/\(+)$ http://betatest.bracknell-forest.gov.uk/ $ 1 [R = 301]

所有查詢字符串參數被刪除,我們確實需要他們(對不起(+) - 網址外部不可用): betatest.bracknell-forest.gov.uk/news.asp?page=2 實際上,我們想要剝離參數的唯一查詢字符串條件是if it co獲取Facebook參數fb_action_ids = 52352315213例如 betatest.bracknell-forest.gov.uk/help?fb_action_ids=372043216205703 & fb_action_types = og.likes & fb_source =聚合& fb_aggregation_id = 288381481237582 我已經嘗試使用:

RewriteCond %{QUERY_STRING}^fb_action_ids=(.)$ [I] 

第一對規則之前但但它似乎沒有做任何事情。

回答

1

只是設法解決它,男孩的感覺就像從我肩膀的負擔:

#key thing I have changed is to specify the query string parameters fb_action_ids and fb_source 
RewriteRule ^/(https?)://([^/]+)(/([^\?]+(\?(.*))?)?)? /$1 
RewriteRule ^/(.+)\?(fb_action_ids=(.*)|fb_source=(.*))$ http://betatest.bracknell-forest.gov.uk/$1 [R=301] 

# e.g. example.com/foo will display the contents of example.com/foo.asp 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.asp -f 
RewriteRule ^(.+)$ $1.asp [L,QSA] 
RedirectRule ^/(.+)\.(asp)$  http://betatest.bracknell-forest.gov.uk/$1 [R=301] 

# Any bare URL will get rewritten to a URL with .htm appended 
RewriteRule ^/([\w]+)$ /$1.htm [I,L] 
RedirectRule ^/(.+)\.(htm)$  http://betatest.bracknell-forest.gov.uk/$1 [R=301]