剥离查询字符串后重写条件不起作用

时间:2012-10-15 18:36:40

标签: mod-rewrite url-rewriting iis-6 iirf

我在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]

我们实际需要它们的所有查询字符串参数都被移除(抱歉 - 网址不可用于外部): 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]

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

1 个答案:

答案 0 :(得分: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]