Added rewrite rule checking and flushing