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]

问题是因为我添加了 RewriteRule ^/(.+)\?(.+)&(.+).(htm)$ /$1
RewriteRule ^/(.+)\?(.+)$ http:/ /betatest.bracknell-forest.gov.uk/ $1 [R=301]

所有查询字符串参数都在我们实际需要它们的地方被删除(抱歉 - url 在外部不可用): betatest.bracknell-forest.gov.uk/news.asp?page=2 实际上我们想要剥离的唯一查询字符串条件参数是它是否包含 Facebook 参数 fb_action_ids=52352315213 例如 betatest.bracknell-forest.gov.uk/help?fb_action_ids=372043216205703&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582 我试过使用:

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

在第一对规则之前,但它似乎没有做任何事情。

4

1 回答 1

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]
于 2012-10-17T16:34:56.010 回答