views:

67

answers:

1

I would like to remove

fb_xd_fragment

from the query string and pass the rest of the request off to the application level. This is for an improved cache hit rate so doing this modification at the application level is not useful nor possible (trust me). Example of how to modify the query string using apache or nginx would be nice.

Example input values

example.com/abcd?page=2&fb_xd_fragment
example.com/abcd?fb_xd_fragment
example.com/abcd?fb_xd_fragment&page=4
example.com/abcd?fb_xd_fragment=xyz&page=6
example.com/abcd?page=8&fb_xd_fragement=xyz
+1  A: 

With mod_rewrite, a RewriteRule can't be used to match a query string, but you can apply a RewriteCond to spot a target query string. Crucially, you can backreference matches in the RewriteCond in the rewrite rule, so try something along these lines:

#     we can refer to this----+-----------------and this--+
#     match as %1 in the      |              match as %2  |
#     RewriteRule             |                           |
                              v                           v
RewriteCond %{QUERY_STRING} ^(.*)fb_xd_fragment=?[a-z]*&?(.*)$
RewriteRule /abcd /abcd?%1%2

The %x in the RewriteRule is a backreference to the last matched RewriteCond. You might need to play around with this to get exactly the effect you want, but you should see the basic principle. Good luck :)

Paul Dixon
any chance of setting an environment variable and using that else where?RewriteRule .* - [E=FILTERED_QUERY:%1%2]
mikeytown2