The technique of a rimshot is when you strike the snare drum primarily, and you catch a portion of the rim, with the head of the drum at the same time. To get a good snare drum rimshot, especially in a groove, what you want to do is use a full stroke, and aim to strike the center of the drum with the tip of your stick. But also catch the rim with the fat part of your stick, with the body of the stick at the same time.
So you're basically aiming to strike the snare in that position. And striking both surfaces exactly at the same time. It's going to sound something like this.
The rimshot is used to basically bring out the sound of your snare drum, and really open up the dynamics of your groove, especially in a rock situation. In other styles like jazz, or Latin, you might not play it as much. But if you're grooving and in a rock feel, it's something you'd want to try to develop.
One last thing to bring up is not to confuse a rimshot with a cross stick or a rim click, and that's another technique to bring down the sound of your snare drum stroke, if you don't want a full stroke off the head. And what that is is actually holding the opposite side of the stick, like this, and laying your entire hand on the snare drum, picking up the back end of the stick and setting it down, to obtain a click sound. It's a very different sound. Remember the rimshot is there to really bring out the dynamics of your stroke.