Religion is the result of uninformed and credulous minds of the past trying to explain the world around them. They would explain the sun sinking on the horizon and rising the next day as a god being infinitely reborn. Lightning as the wrath of their god. As time went on, the small communities got dedicated priests or shamen who would claim to know what the gods wanted, having realised that doing so would gain them food, shelter and comforts without having to work for them. They began to expand on their mythology with more stories, and to write down 'laws' from their gods which they thought were good laws for the people.(although they usually made them suit themselves more than others, eg the extremely harsh laws relating to women from the OT).
The stories got larger and wilder in re-telling, but people kept believing them because they did not know any better. Sometimes people claimed to be the reincarnation of gods/ gods manifestation on earth (still happens nowadays - Jim Jones, Marshall Applewhite etc) - which was sometimes unsuccessful (all the failed christs of around 0-100 CE) and sometimes it was successful ('Jesus' Christ.)
As the stories developed, complex organisations sprung up around them, all dedicated more to improvingtheir own lot than helping people (EG catholic church was the richest organisation in the world until Mr Gates started his empire).
As the ordinary people began getting educated, they started learning that the sun was not, in fact, pushed by a giant dung beetle, or a celestial chariot, or a god being re-born every day. They learned how things worked where previously it was just said 'ah, god did it' and the places for gods to 'be' became smaller and smaller.
What is religion? Religion is a bullshit story designed to impress peasants thousands of years ago that does not mean anything today.