Suppose that I have $6$ different books, 2 of which are math books. In how many ways can I stack my 6 books on a shelf if I do not want the math books to be at the ends?
There are 6! number of ways you can stack your 6 books. However, you don't want the math books to be on the ends of the stack, so:
--> There are 4P2 ways to order the ends of the stack
--> There are 4! ways to order the middle of the stack
Which means your answer is 12 * 4!, which equals 288
Hope this helps :)