SEF add_rewrite_rule & add_rewrite_tag not working

I’m making SEF urls for my plugin. To logic is: if there is my_shortcode on the page, then pass the rest of url as parametr dir=
This code is perfectly works on one of my wordpress installations and not working on another. I got 404. What can be wrong on it?

P.s. redirect rules flushed

UPDATE:
Anyone can explain me what’s happening? I commented those 2 if’s:

and redirects starts working. Then I returned it back.. and it keeps working!