How to make a url to Apple app store or Google play to actually open the app store?

For Android apps, you can just link to the Google play store directly. The Android OS will prompt the user if they want to open the link in their browser or open the link in the Google Play store app as soon as they click on it. Any http://play.google.com?id=* link will prompt the user in this way on an Android device.

If you've got an Android phone, just give it a try with this link to the Facebook app for Android

For iPhone, check out this answer that is very complete for what you want to do.