Yes, it is legal for both handguns and rifles. Here is the applicable law. See example #2:
TITLE 27--ALCOHOL, TOBACCO PRODUCTS, AND FIREARMS
CHAPTER II--BUREAU OF ALCOHOL, TOBACCO, FIREARMS, AND EXPLOSIVES,
DEPARTMENT OF JUSTICE
PART 478_COMMERCE IN FIREARMS AND AMMUNITION--Table of Contents
Subpart B_Definitions
Sec. 478.11 Meaning of terms.
State of residence. The State in which an individual resides. An
individual resides in a State if he or she is present in a State with
the intention of making a home in that State. If an individual is on
active duty as a member of the Armed Forces, the individual's State of
residence is the State in which his or her permanent duty station is
located. An alien who is legally in the United States shall be
considered to be a resident of a State only if the alien is residing in
the State and has resided in the State for a period of at least 90 days
prior to the date of sale or delivery of a firearm. The following are
examples that illustrate this definition:
Example 1. A maintains a home in State X. A travels to State Y on a
hunting, fishing, business, or other type of trip. A does not become a
resident of State Y by reason of such trip.
Example 2. A is a U.S. citizen and maintains a home in State X and a
home in State Y. A resides in State X except for weekends or the summer
months of the year and in State Y for the weekends or the summer months
of the year. During the time that A actually resides in State X, A is a
resident of State X, and during the time that A actually resides in
State Y, A is a resident of State Y.
Example 3. A, an alien, travels on vacation or on a business trip to
State X. Regardless of the length of time A spends in State X, A does
not have a State of residence in State X. This is because A does not
have a home in State X at which he has resided for at least 90 days.